File tree 5 files changed +49
-0
lines changed
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> {
401
401
* self = LinkedList :: new ( )
402
402
}
403
403
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
+
404
414
/// Provides a reference to the front element, or `None` if the list is
405
415
/// empty.
406
416
///
Original file line number Diff line number Diff line change @@ -872,6 +872,17 @@ impl<T> VecDeque<T> {
872
872
self . drain ( ..) ;
873
873
}
874
874
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
+
875
886
/// Provides a reference to the front element, or `None` if the sequence is
876
887
/// empty.
877
888
///
Original file line number Diff line number Diff line change 21
21
#![ feature( fn_traits) ]
22
22
#![ feature( enumset) ]
23
23
#![ feature( iter_arith) ]
24
+ #![ feature( linked_list_contains) ]
24
25
#![ feature( map_entry_keys) ]
25
26
#![ feature( map_values_mut) ]
26
27
#![ feature( pattern) ]
32
33
#![ feature( test) ]
33
34
#![ feature( unboxed_closures) ]
34
35
#![ feature( unicode) ]
36
+ #![ feature( vec_deque_contains) ]
35
37
36
38
extern crate collections;
37
39
extern 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) {
413
413
assert ! ( m. iter_mut( ) . rev( ) . count( ) == 128 ) ;
414
414
} )
415
415
}
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() {
959
959
assert_eq ! ( v[ 4 ] , 5 ) ;
960
960
assert_eq ! ( v[ 5 ] , 6 ) ;
961
961
}
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