about summary refs log tree commit diff
path: root/src/libcollections
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-04-20 04:58:44 -0700
committerbors <bors@rust-lang.org>2016-04-20 04:58:44 -0700
commit133f60f82012ad92c40693bf1ae28419b60146a7 (patch)
tree3bbb49eca49537bd9ceb893d8598edaa1e370c29 /src/libcollections
parent9bba2907ee712753e44d7e248560031c190724e0 (diff)
parentbf3aefeba0bc72d1e26d36a7d88e2995e460bc1d (diff)
downloadrust-133f60f82012ad92c40693bf1ae28419b60146a7.tar.gz
rust-133f60f82012ad92c40693bf1ae28419b60146a7.zip
Auto merge of #32951 - LukasKalbertodt:collection_contains_rfc1552, r=brson
Add `contains` to `VecDeque` and `LinkedList` (+ tests)

This implements [RFC 1552](https://github.com/rust-lang/rfcs/blob/master/text/1552-contains-method-for-various-collections.md). Tracking issue: #32630

Sorry for the late response. This is my first contribution, so please tell me if anything isn't optimal!
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 c974be54bd0..406b979a370 100644
--- a/src/libcollections/linked_list.rs
+++ b/src/libcollections/linked_list.rs
@@ -403,6 +403,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 6e8f4391eeb..84a0bbbd249 100644
--- a/src/libcollections/vec_deque.rs
+++ b/src/libcollections/vec_deque.rs
@@ -873,6 +873,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.
     ///