1
+ use crate :: cmp:: Ordering ;
1
2
use crate :: iter:: adapters:: zip:: try_get_unchecked;
2
3
use crate :: iter:: adapters:: { SourceIter , TrustedRandomAccess , TrustedRandomAccessNoCoerce } ;
3
4
use crate :: iter:: { FusedIterator , InPlaceIterable , TrustedLen } ;
@@ -48,20 +49,35 @@ where
48
49
49
50
fn next_chunk < const N : usize > (
50
51
& mut self ,
51
- ) -> Result < [ Self :: Item ; N ] , array:: IntoIter < Self :: Item , N > >
52
- where
53
- Self : Sized ,
54
- {
52
+ ) -> Result < [ Self :: Item ; N ] , array:: IntoIter < Self :: Item , N > > {
55
53
<I as SpecNextChunk < ' _ , N , T > >:: spec_next_chunk ( & mut self . it )
56
54
}
57
55
56
+ #[ inline]
58
57
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
59
58
self . it . size_hint ( )
60
59
}
61
60
61
+ #[ inline]
62
+ fn count ( self ) -> usize {
63
+ self . it . count ( )
64
+ }
65
+
66
+ fn last ( self ) -> Option < T > {
67
+ self . it . last ( ) . copied ( )
68
+ }
69
+
70
+ #[ inline]
71
+ fn advance_by ( & mut self , n : usize ) -> Result < ( ) , NonZero < usize > > {
72
+ self . it . advance_by ( n)
73
+ }
74
+
75
+ fn nth ( & mut self , n : usize ) -> Option < T > {
76
+ self . it . nth ( n) . copied ( )
77
+ }
78
+
62
79
fn try_fold < B , F , R > ( & mut self , init : B , f : F ) -> R
63
80
where
64
- Self : Sized ,
65
81
F : FnMut ( B , Self :: Item ) -> R ,
66
82
R : Try < Output = B > ,
67
83
{
@@ -75,21 +91,58 @@ where
75
91
self . it . fold ( init, copy_fold ( f) )
76
92
}
77
93
78
- fn nth ( & mut self , n : usize ) -> Option < T > {
79
- self . it . nth ( n) . copied ( )
94
+ fn find < P > ( & mut self , mut predicate : P ) -> Option < Self :: Item >
95
+ where
96
+ P : FnMut ( & Self :: Item ) -> bool ,
97
+ {
98
+ self . it . find ( move |x| predicate ( & x) ) . copied ( )
80
99
}
81
100
82
- fn last ( self ) -> Option < T > {
83
- self . it . last ( ) . copied ( )
101
+ // FIXME: Implement try_find
102
+
103
+ fn max_by < F > ( self , mut compare : F ) -> Option < Self :: Item >
104
+ where
105
+ F : FnMut ( & Self :: Item , & Self :: Item ) -> Ordering ,
106
+ {
107
+ self . it . max_by ( move |& x, & y| compare ( x, y) ) . copied ( )
84
108
}
85
109
86
- fn count ( self ) -> usize {
87
- self . it . count ( )
110
+ fn min_by < F > ( self , mut compare : F ) -> Option < Self :: Item >
111
+ where
112
+ F : FnMut ( & Self :: Item , & Self :: Item ) -> Ordering ,
113
+ {
114
+ self . it . min_by ( move |& x, & y| compare ( x, y) ) . copied ( )
88
115
}
89
116
90
- #[ inline]
91
- fn advance_by ( & mut self , n : usize ) -> Result < ( ) , NonZero < usize > > {
92
- self . it . advance_by ( n)
117
+ fn cmp < O > ( self , other : O ) -> Ordering
118
+ where
119
+ O : IntoIterator < Item = Self :: Item > ,
120
+ Self :: Item : Ord ,
121
+ {
122
+ self . it . cmp_by ( other, |x, y| x. cmp ( & y) )
123
+ }
124
+
125
+ fn partial_cmp < O > ( self , other : O ) -> Option < Ordering >
126
+ where
127
+ O : IntoIterator ,
128
+ Self :: Item : PartialOrd < O :: Item > ,
129
+ {
130
+ self . it . partial_cmp_by ( other, |x, y| x. partial_cmp ( & y) )
131
+ }
132
+
133
+ fn eq < O > ( self , other : O ) -> bool
134
+ where
135
+ O : IntoIterator ,
136
+ Self :: Item : PartialEq < O :: Item > ,
137
+ {
138
+ self . it . eq_by ( other, |x, y| x == & y)
139
+ }
140
+
141
+ fn is_sorted_by < F > ( self , mut compare : F ) -> bool
142
+ where
143
+ F : FnMut ( & Self :: Item , & Self :: Item ) -> bool ,
144
+ {
145
+ self . it . is_sorted_by ( move |& x, & y| compare ( x, y) )
93
146
}
94
147
95
148
unsafe fn __iterator_get_unchecked ( & mut self , idx : usize ) -> T
@@ -112,9 +165,13 @@ where
112
165
self . it . next_back ( ) . copied ( )
113
166
}
114
167
168
+ #[ inline]
169
+ fn advance_back_by ( & mut self , n : usize ) -> Result < ( ) , NonZero < usize > > {
170
+ self . it . advance_back_by ( n)
171
+ }
172
+
115
173
fn try_rfold < B , F , R > ( & mut self , init : B , f : F ) -> R
116
174
where
117
- Self : Sized ,
118
175
F : FnMut ( B , Self :: Item ) -> R ,
119
176
R : Try < Output = B > ,
120
177
{
@@ -128,9 +185,11 @@ where
128
185
self . it . rfold ( init, copy_fold ( f) )
129
186
}
130
187
131
- #[ inline]
132
- fn advance_back_by ( & mut self , n : usize ) -> Result < ( ) , NonZero < usize > > {
133
- self . it . advance_back_by ( n)
188
+ fn rfind < P > ( & mut self , mut predicate : P ) -> Option < Self :: Item >
189
+ where
190
+ P : FnMut ( & Self :: Item ) -> bool ,
191
+ {
192
+ self . it . rfind ( move |x| predicate ( & x) ) . copied ( )
134
193
}
135
194
}
136
195
@@ -140,10 +199,12 @@ where
140
199
I : ExactSizeIterator < Item = & ' a T > ,
141
200
T : Copy ,
142
201
{
202
+ #[ inline]
143
203
fn len ( & self ) -> usize {
144
204
self . it . len ( )
145
205
}
146
206
207
+ #[ inline]
147
208
fn is_empty ( & self ) -> bool {
148
209
self . it . is_empty ( )
149
210
}
0 commit comments