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 @@ -403,6 +403,16 @@ impl<T> LinkedList<T> {
403403 * self = LinkedList :: new ( )
404404 }
405405
406+ /// Returns `true` if the `LinkedList` contains an element equal to the
407+ /// given value.
408+ #[ unstable( feature = "linked_list_contains" , reason = "recently added" ,
409+ issue = "32630" ) ]
410+ pub fn contains ( & self , x : & T ) -> bool
411+ where T : PartialEq < T >
412+ {
413+ self . iter ( ) . any ( |e| e == x)
414+ }
415+
406416 /// Provides a reference to the front element, or `None` if the list is
407417 /// empty.
408418 ///
Original file line number Diff line number Diff line change @@ -873,6 +873,17 @@ impl<T> VecDeque<T> {
873873 self . drain ( ..) ;
874874 }
875875
876+ /// Returns `true` if the `VecDeque` contains an element equal to the
877+ /// given value.
878+ #[ unstable( feature = "vec_deque_contains" , reason = "recently added" ,
879+ issue = "32630" ) ]
880+ pub fn contains ( & self , x : & T ) -> bool
881+ where T : PartialEq < T >
882+ {
883+ let ( a, b) = self . as_slices ( ) ;
884+ a. contains ( x) || b. contains ( x)
885+ }
886+
876887 /// Provides a reference to the front element, or `None` if the sequence is
877888 /// empty.
878889 ///
Original file line number Diff line number Diff line change 2020#![ feature( fn_traits) ]
2121#![ feature( enumset) ]
2222#![ feature( iter_arith) ]
23+ #![ feature( linked_list_contains) ]
2324#![ feature( map_entry_keys) ]
2425#![ feature( map_values_mut) ]
2526#![ feature( pattern) ]
3031#![ feature( test) ]
3132#![ feature( unboxed_closures) ]
3233#![ feature( unicode) ]
34+ #![ feature( vec_deque_contains) ]
3335
3436extern crate collections;
3537extern crate test;
Original file line number Diff line number Diff line change @@ -429,3 +429,16 @@ fn bench_iter_mut_rev(b: &mut test::Bencher) {
429429 assert ! ( m. iter_mut( ) . rev( ) . count( ) == 128 ) ;
430430 } )
431431}
432+
433+ #[ test]
434+ fn test_contains ( ) {
435+ let mut l = LinkedList :: new ( ) ;
436+ l. extend ( & [ 2 , 3 , 4 ] ) ;
437+
438+ assert ! ( l. contains( & 3 ) ) ;
439+ assert ! ( !l. contains( & 1 ) ) ;
440+
441+ l. clear ( ) ;
442+
443+ assert ! ( !l. contains( & 3 ) ) ;
444+ }
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