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 @@ -403,6 +403,16 @@ impl<T> LinkedList<T> {
403
403
* self = LinkedList :: new ( )
404
404
}
405
405
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
+
406
416
/// Provides a reference to the front element, or `None` if the list is
407
417
/// empty.
408
418
///
Original file line number Diff line number Diff line change @@ -873,6 +873,17 @@ impl<T> VecDeque<T> {
873
873
self . drain ( ..) ;
874
874
}
875
875
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
+
876
887
/// Provides a reference to the front element, or `None` if the sequence is
877
888
/// empty.
878
889
///
Original file line number Diff line number Diff line change 20
20
#![ feature( fn_traits) ]
21
21
#![ feature( enumset) ]
22
22
#![ feature( iter_arith) ]
23
+ #![ feature( linked_list_contains) ]
23
24
#![ feature( map_entry_keys) ]
24
25
#![ feature( map_values_mut) ]
25
26
#![ feature( pattern) ]
30
31
#![ feature( test) ]
31
32
#![ feature( unboxed_closures) ]
32
33
#![ feature( unicode) ]
34
+ #![ feature( vec_deque_contains) ]
33
35
34
36
extern crate collections;
35
37
extern 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) {
429
429
assert ! ( m. iter_mut( ) . rev( ) . count( ) == 128 ) ;
430
430
} )
431
431
}
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() {
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