How to check if there are duplicates in a slice?
问题 Is there a native way to check if a slice has duplicates? For now, I use this: fn has_dup<T: PartialEq>(slice: &[T]) -> bool { for i in 1..slice.len() { if slice[i..].contains(&slice[i - 1]) { return true; } } false } fn main() { assert_eq!(has_dup(&[1, 2, 3, 2, 5, 6]), true); assert_eq!(has_dup(&[1, 2, 3, 4, 5, 6]), false); } but for this kind of basic operations, I do not like to use hand-made code. If there is no available function to do this in the standard library, is it a way to