We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2c28244 commit 15bc9b6Copy full SHA for 15bc9b6
library/core/src/slice/mod.rs
@@ -1407,6 +1407,23 @@ impl<T> [T] {
1407
x.slice_contains(self)
1408
}
1409
1410
+ /// Returns `true` if the slice contains an element with the given value.
1411
+ ///
1412
+ /// # Examples
1413
1414
+ /// ```
1415
+ /// let v = [String::from("Hello"), String::from("world")];
1416
+ /// assert!(v.contains_ref("Hello"));
1417
+ /// assert!(!v.contains_ref("Rust"));
1418
1419
+ #[unstable(feature = "contains_ref", issue = "none")]
1420
+ pub fn contains_ref<U>(&self, x: &U) -> bool
1421
+ where
1422
+ T: PartialEq<U>,
1423
+ {
1424
+ self.iter().any(|e| e == x)
1425
+ }
1426
+
1427
/// Returns `true` if `needle` is a prefix of the slice.
1428
///
1429
/// # Examples
0 commit comments