We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 9785008 + 3f77f2c commit 966ba8dCopy full SHA for 966ba8d
src/libcore/slice/mod.rs
@@ -1263,6 +1263,15 @@ impl<T> [T] {
1263
/// assert!(v.contains(&30));
1264
/// assert!(!v.contains(&50));
1265
/// ```
1266
+ ///
1267
+ /// If you do not have an `&T`, but just an `&U` such that `T: Borrow<U>`
1268
+ /// (e.g. `String: Borrow<str>`), you can use `iter().any`:
1269
1270
+ /// ```
1271
+ /// let v = [String::from("hello"), String::from("world")]; // slice of `String`
1272
+ /// assert!(v.iter().any(|e| e == "hello")); // search with `&str`
1273
+ /// assert!(!v.iter().any(|e| e == "hi"));
1274
1275
#[stable(feature = "rust1", since = "1.0.0")]
1276
pub fn contains(&self, x: &T) -> bool
1277
where T: PartialEq
0 commit comments