diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 9ed5a1f962215..a5baf542f017f 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -1407,6 +1407,25 @@ impl [T] { x.slice_contains(self) } + /// Returns `true` if the slice contains an element with the given value. + /// + /// # Examples + /// + /// ``` + /// #![feature(contains_ref)] + /// let v = [String::from("Hello"), String::from("world")]; + /// assert!(v.contains_ref("Hello")); + /// assert!(!v.contains_ref("Rust")); + /// ``` + #[unstable(feature = "contains_ref", issue = "none")] + pub fn contains_ref(&self, x: &U) -> bool + where + T: PartialEq, + U: ?Sized, + { + self.iter().any(|e| e == x) + } + /// Returns `true` if `needle` is a prefix of the slice. /// /// # Examples