str_utils/ends_with_multiple.rs
1/// To extend types which implement `AsRef<[u8]>` to have a `ends_with_multiple` method.
2pub trait EndsWithMultiple {
3 /// Returns `Some(usize)` if one of the given string slices case-sensitively matches a suffix of this string slice.
4 fn ends_with_multiple<S: AsRef<[u8]>>(&self, bs: &[S]) -> Option<usize>;
5}
6
7impl<T: AsRef<[u8]>> EndsWithMultiple for T {
8 #[inline]
9 fn ends_with_multiple<S: AsRef<[u8]>>(&self, bs: &[S]) -> Option<usize> {
10 let a = self.as_ref();
11
12 bs.iter().position(|b| a.ends_with(b.as_ref()))
13 }
14}