str_utils/
eq_multiple.rs

1/// To extend `[u8]` and `str` to have a `eq_multiple` method.
2pub trait EqMultiple {
3    /// Returns `Some(usize)` if one of the given string slices case-sensitively matches this string slice.
4    fn eq_multiple<S: AsRef<[u8]>>(&self, bs: &[S]) -> Option<usize>;
5}
6
7impl EqMultiple for [u8] {
8    #[inline]
9    fn eq_multiple<S: AsRef<[u8]>>(&self, bs: &[S]) -> Option<usize> {
10        let a = self;
11
12        bs.iter().position(|b| a == b.as_ref())
13    }
14}
15
16impl EqMultiple for str {
17    #[inline]
18    fn eq_multiple<S: AsRef<[u8]>>(&self, bs: &[S]) -> Option<usize> {
19        self.as_bytes().eq_multiple(bs)
20    }
21}