about summary refs log tree commit diff
path: root/src/libcollections
diff options
context:
space:
mode:
authorLukas Kalbertodt <lukas.kalbertodt@gmail.com>2016-04-14 16:07:53 +0200
committerLukas Kalbertodt <lukas.kalbertodt@gmail.com>2016-04-14 16:07:53 +0200
commitbf3aefeba0bc72d1e26d36a7d88e2995e460bc1d (patch)
tree4bb3d864cb0bc446bba733f777e81b0796624bc9 /src/libcollections
parent28c9fdafc06a259c25c1b889044fd49b4dfc69e2 (diff)
Add `contains` to `VecDeque` and `LinkedList` (+ tests)
Diffstat (limited to 'src/libcollections')
-rw-r--r--src/libcollections/linked_list.rs10
-rw-r--r--src/libcollections/vec_deque.rs11
2 files changed, 21 insertions, 0 deletions
diff --git a/src/libcollections/linked_list.rs b/src/libcollections/linked_list.rs
index 85a4fa82e2a..17d3dbc10c4 100644
--- a/src/libcollections/linked_list.rs
+++ b/src/libcollections/linked_list.rs
@@ -401,6 +401,16 @@ impl<T> LinkedList<T> {
         *self = LinkedList::new()
     }
 
+    /// Returns `true` if the `LinkedList` contains an element equal to the
+    /// given value.
+    #[unstable(feature = "linked_list_contains", reason = "recently added",
+               issue = "32630")]
+    pub fn contains(&self, x: &T) -> bool
+        where T: PartialEq<T>
+    {
+        self.iter().any(|e| e == x)
+    }
+
     /// Provides a reference to the front element, or `None` if the list is
     /// empty.
     ///
diff --git a/src/libcollections/vec_deque.rs b/src/libcollections/vec_deque.rs
index 9e2b25d178f..45b4f0c958b 100644
--- a/src/libcollections/vec_deque.rs
+++ b/src/libcollections/vec_deque.rs
@@ -872,6 +872,17 @@ impl<T> VecDeque<T> {
         self.drain(..);
     }
 
+    /// Returns `true` if the `VecDeque` contains an element equal to the
+    /// given value.
+    #[unstable(feature = "vec_deque_contains", reason = "recently added",
+               issue = "32630")]
+    pub fn contains(&self, x: &T) -> bool
+        where T: PartialEq<T>
+    {
+        let (a, b) = self.as_slices();
+        a.contains(x) || b.contains(x)
+    }
+
     /// Provides a reference to the front element, or `None` if the sequence is
     /// empty.
     ///