]> git.lizzy.rs Git - rust.git/commitdiff
explain how to search without owned data
authorRalf Jung <post@ralfj.de>
Sat, 13 Jul 2019 13:16:05 +0000 (15:16 +0200)
committerRalf Jung <post@ralfj.de>
Sat, 13 Jul 2019 13:16:05 +0000 (15:16 +0200)
src/libcore/slice/mod.rs

index 363ae088275586239e95a53f337b0e9c2ab1905b..c3eb2ec9dc251b611bc4a67d3d65632112819ab6 100644 (file)
@@ -1263,6 +1263,14 @@ pub fn rsplitn_mut<F>(&mut self, n: usize, pred: F) -> RSplitNMut<'_, T, F>
     /// 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