index_of

Crates.ioindex_of
lib.rsindex_of
version0.1.1
created_at2025-03-10 08:41:38.74175+00
updated_at2025-03-10 08:41:38.74175+00
descriptionindex_of
homepagehttps://github.com/i18n-site/rust/tree/dev/index_of
repositoryhttps://github.com/i18n-site/rust.git
max_upload_size
id1586341
size20,515
i18n.site (i18nsite)

documentation

README

index_of

pub trait IndexOf<T> {
  fn index_of(&self, target: &T) -> Option<usize>;
}

impl<T: PartialEq> IndexOf<T> for &[T] {
  fn index_of(&self, target: &T) -> Option<usize> {
    for (i, x) in self.iter().enumerate() {
      if x == target {
        return Some(i);
      }
    }
    None
  }
}

impl<T: PartialEq, const N: usize> IndexOf<T> for [T; N] {
  fn index_of(&self, target: &T) -> Option<usize> {
    for (i, x) in self.iter().enumerate() {
      if x == target {
        return Some(i);
      }
    }
    None
  }
}

About

This project is an open-source component of i18n.site ⋅ Internationalization Solution.

关于

本项目为 i18n.site ⋅ 国际化解决方案 的开源组件。

Commit count: 68

cargo fmt