Skip to content

Commit d73c23d

Browse files
committed
explain how to search without owned data
1 parent 4a95e97 commit d73c23d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/libcore/slice/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,14 @@ impl<T> [T] {
12631263
/// assert!(v.contains(&30));
12641264
/// assert!(!v.contains(&50));
12651265
/// ```
1266+
///
1267+
/// If you only have a borrowed `T`, use `any`:
1268+
///
1269+
/// ```
1270+
/// let v = [String::from("hello"), String::from("world")];
1271+
/// assert!(v.iter().any(|e| e == "hello"));
1272+
/// assert!(!v.iter().any(|e| e == "hi"));
1273+
/// ```
12661274
#[stable(feature = "rust1", since = "1.0.0")]
12671275
pub fn contains(&self, x: &T) -> bool
12681276
where T: PartialEq

0 commit comments

Comments
 (0)