aboutsummaryrefslogtreecommitdiff
path: root/libcollections/linked_list.rs
diff options
context:
space:
mode:
authorpravic <[email protected]>2016-04-29 21:16:15 +0300
committerpravic <[email protected]>2016-04-29 21:16:15 +0300
commit77e9a3167b4aaadf3583a0c1d1ee0d9e63c9a000 (patch)
tree710e445d56a1a582b8eff19b7b4b180276eae122 /libcollections/linked_list.rs
parenttweak: /driver option specifies /fixed:no implicitly as well (diff)
downloadkmd-env-rs-77e9a3167b4aaadf3583a0c1d1ee0d9e63c9a000.tar.xz
kmd-env-rs-77e9a3167b4aaadf3583a0c1d1ee0d9e63c9a000.zip
update libcore to 2016-04-29 nightly
Diffstat (limited to 'libcollections/linked_list.rs')
-rw-r--r--libcollections/linked_list.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/libcollections/linked_list.rs b/libcollections/linked_list.rs
index 85a4fa8..406b979 100644
--- a/libcollections/linked_list.rs
+++ b/libcollections/linked_list.rs
@@ -30,6 +30,8 @@ use core::mem;
use core::ops::{BoxPlace, InPlace, Place, Placer};
use core::ptr::{self, Shared};
+use super::SpecExtend;
+
/// A doubly-linked list.
#[stable(feature = "rust1", since = "1.0.0")]
pub struct LinkedList<T> {
@@ -401,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.
///
@@ -969,12 +981,24 @@ impl<'a, T> IntoIterator for &'a mut LinkedList<T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<A> Extend<A> for LinkedList<A> {
fn extend<T: IntoIterator<Item = A>>(&mut self, iter: T) {
+ <Self as SpecExtend<T>>::spec_extend(self, iter);
+ }
+}
+
+impl<I: IntoIterator> SpecExtend<I> for LinkedList<I::Item> {
+ default fn spec_extend(&mut self, iter: I) {
for elt in iter {
self.push_back(elt);
}
}
}
+impl<T> SpecExtend<LinkedList<T>> for LinkedList<T> {
+ fn spec_extend(&mut self, ref mut other: LinkedList<T>) {
+ self.append(other);
+ }
+}
+
#[stable(feature = "extend_ref", since = "1.2.0")]
impl<'a, T: 'a + Copy> Extend<&'a T> for LinkedList<T> {
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {