1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
//! TODO: write documentation. #[cfg(test)] mod test; pub trait SameElements<T> { fn same_elements(self, other: Self) -> bool; } impl<T> SameElements<T> for &[T] where T: PartialEq, { fn same_elements(self, other: Self) -> bool { // Not the same length. if self.len() != other.len() { return false; } // Not all elements are found in the other slice. for elem in self.iter() { if !other.contains(elem) { return false; } } // Slices contain the same elements. true } }