about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2019-07-13 15:16:05 +0200
committerRalf Jung <post@ralfj.de>2019-07-13 15:16:05 +0200
commitd73c23d114d109d7c48c9447f53bcba533effa16 (patch)
treedf38b216d4c4760b1308d1ed10b596e9a5541de4 /src/libcore
parent4a95e9704de0eeaecba55df102c1129e79a3a929 (diff)
downloadrust-d73c23d114d109d7c48c9447f53bcba533effa16.tar.gz
rust-d73c23d114d109d7c48c9447f53bcba533effa16.zip
explain how to search without owned data
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/slice/mod.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs
index 363ae088275..c3eb2ec9dc2 100644
--- a/src/libcore/slice/mod.rs
+++ b/src/libcore/slice/mod.rs
@@ -1263,6 +1263,14 @@ impl<T> [T] {
     /// assert!(v.contains(&30));
     /// assert!(!v.contains(&50));
     /// ```
+    ///
+    /// If you only have a borrowed `T`, use `any`:
+    ///
+    /// ```
+    /// let v = [String::from("hello"), String::from("world")];
+    /// assert!(v.iter().any(|e| e == "hello"));
+    /// assert!(!v.iter().any(|e| e == "hi"));
+    /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn contains(&self, x: &T) -> bool
         where T: PartialEq