File tree 2 files changed +48
-0
lines changed
2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 11
11
use fmt;
12
12
use marker;
13
13
use usize;
14
+ use cmp:: Ordering ;
14
15
15
16
use super :: { FusedIterator , TrustedLen } ;
16
17
@@ -31,8 +32,41 @@ impl<A: Clone> Iterator for Repeat<A> {
31
32
32
33
#[ inline]
33
34
fn next ( & mut self ) -> Option < A > { Some ( self . element . clone ( ) ) }
35
+
34
36
#[ inline]
35
37
fn size_hint ( & self ) -> ( usize , Option < usize > ) { ( usize:: MAX , None ) }
38
+
39
+ #[ inline]
40
+ fn nth ( & mut self , _: usize ) -> Option < A > { self . next ( ) }
41
+
42
+ #[ inline]
43
+ fn all < F > ( & mut self , f : F ) -> bool where F : FnMut ( A ) -> bool { self . any ( f) }
44
+
45
+ #[ inline]
46
+ fn max ( mut self ) -> Option < A > { self . next ( ) }
47
+
48
+ #[ inline]
49
+ fn min ( mut self ) -> Option < A > { self . next ( ) }
50
+
51
+ #[ inline]
52
+ fn max_by_key < B : Ord , F > ( mut self , _: F ) -> Option < A > where F : FnMut ( & A ) -> B {
53
+ self . next ( )
54
+ }
55
+
56
+ #[ inline]
57
+ fn max_by < F > ( mut self , _: F ) -> Option < A > where F : FnMut ( & A , & A ) -> Ordering {
58
+ self . next ( )
59
+ }
60
+
61
+ #[ inline]
62
+ fn min_by_key < B : Ord , F > ( mut self , _: F ) -> Option < A > where F : FnMut ( & A ) -> B {
63
+ self . next ( )
64
+ }
65
+
66
+ #[ inline]
67
+ fn min_by < F > ( mut self , _: F ) -> Option < A > where F : FnMut ( & A , & A ) -> Ordering {
68
+ self . next ( )
69
+ }
36
70
}
37
71
38
72
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
Original file line number Diff line number Diff line change 11
11
use core:: iter:: * ;
12
12
use core:: { i8, i16, isize} ;
13
13
use core:: usize;
14
+ use std:: cmp:: Ordering ;
14
15
15
16
#[ test]
16
17
fn test_lt ( ) {
@@ -1405,6 +1406,19 @@ fn test_repeat() {
1405
1406
assert_eq ! ( it. next( ) , Some ( 42 ) ) ;
1406
1407
}
1407
1408
1409
+ #[ test]
1410
+ fn test_repeat_iterator ( ) {
1411
+ let mut it = repeat ( 42 ) ;
1412
+ assert_eq ! ( it. nth( usize :: MAX ) , Some ( 42 ) ) ;
1413
+ assert_eq ! ( it. all( |x| x == 42 ) , true ) ;
1414
+ assert_eq ! ( repeat( 42 ) . max( ) , Some ( 42 ) ) ;
1415
+ assert_eq ! ( repeat( 42 ) . min( ) , Some ( 42 ) ) ;
1416
+ assert_eq ! ( repeat( 42 ) . max_by_key( |_| 0 ) , Some ( 42 ) ) ;
1417
+ assert_eq ! ( repeat( 42 ) . max_by_key( |_| Ordering :: Greater ) , Some ( 42 ) ) ;
1418
+ assert_eq ! ( repeat( 42 ) . min_by_key( |_| 0 ) , Some ( 42 ) ) ;
1419
+ assert_eq ! ( repeat( 42 ) . min_by_key( |_| Ordering :: Greater ) , Some ( 42 ) ) ;
1420
+ }
1421
+
1408
1422
#[ test]
1409
1423
fn test_fuse ( ) {
1410
1424
let mut it = 0 ..3 ;
You can’t perform that action at this time.
0 commit comments