File tree Expand file tree Collapse file tree 5 files changed +49
-0
lines changed Expand file tree Collapse file tree 5 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -401,6 +401,16 @@ impl<T> LinkedList<T> {
401401 * self = LinkedList :: new ( )
402402 }
403403
404+ /// Returns `true` if the `LinkedList` contains an element equal to the
405+ /// given value.
406+ #[ unstable( feature = "linked_list_contains" , reason = "recently added" ,
407+ issue = "32630" ) ]
408+ pub fn contains ( & self , x : & T ) -> bool
409+ where T : PartialEq < T >
410+ {
411+ self . iter ( ) . any ( |e| e == x)
412+ }
413+
404414 /// Provides a reference to the front element, or `None` if the list is
405415 /// empty.
406416 ///
Original file line number Diff line number Diff line change @@ -872,6 +872,17 @@ impl<T> VecDeque<T> {
872872 self . drain ( ..) ;
873873 }
874874
875+ /// Returns `true` if the `VecDeque` contains an element equal to the
876+ /// given value.
877+ #[ unstable( feature = "vec_deque_contains" , reason = "recently added" ,
878+ issue = "32630" ) ]
879+ pub fn contains ( & self , x : & T ) -> bool
880+ where T : PartialEq < T >
881+ {
882+ let ( a, b) = self . as_slices ( ) ;
883+ a. contains ( x) || b. contains ( x)
884+ }
885+
875886 /// Provides a reference to the front element, or `None` if the sequence is
876887 /// empty.
877888 ///
Original file line number Diff line number Diff line change 2121#![ feature( fn_traits) ]
2222#![ feature( enumset) ]
2323#![ feature( iter_arith) ]
24+ #![ feature( linked_list_contains) ]
2425#![ feature( map_entry_keys) ]
2526#![ feature( map_values_mut) ]
2627#![ feature( pattern) ]
3233#![ feature( test) ]
3334#![ feature( unboxed_closures) ]
3435#![ feature( unicode) ]
36+ #![ feature( vec_deque_contains) ]
3537
3638extern crate collections;
3739extern crate test;
Original file line number Diff line number Diff line change @@ -413,3 +413,16 @@ fn bench_iter_mut_rev(b: &mut test::Bencher) {
413413 assert ! ( m. iter_mut( ) . rev( ) . count( ) == 128 ) ;
414414 } )
415415}
416+
417+ #[ test]
418+ fn test_contains ( ) {
419+ let mut l = LinkedList :: new ( ) ;
420+ l. extend ( & [ 2 , 3 , 4 ] ) ;
421+
422+ assert ! ( l. contains( & 3 ) ) ;
423+ assert ! ( !l. contains( & 1 ) ) ;
424+
425+ l. clear ( ) ;
426+
427+ assert ! ( !l. contains( & 3 ) ) ;
428+ }
Original file line number Diff line number Diff line change @@ -959,3 +959,16 @@ fn test_extend_ref() {
959959 assert_eq ! ( v[ 4 ] , 5 ) ;
960960 assert_eq ! ( v[ 5 ] , 6 ) ;
961961}
962+
963+ #[ test]
964+ fn test_contains ( ) {
965+ let mut v = VecDeque :: new ( ) ;
966+ v. extend ( & [ 2 , 3 , 4 ] ) ;
967+
968+ assert ! ( v. contains( & 3 ) ) ;
969+ assert ! ( !v. contains( & 1 ) ) ;
970+
971+ v. clear ( ) ;
972+
973+ assert ! ( !v. contains( & 3 ) ) ;
974+ }
You can’t perform that action at this time.
0 commit comments