@@ -105,139 +105,31 @@ impl Default for Generics {
105
105
impl Generics {
106
106
/// Iterator over the lifetime parameters in `self.params`.
107
107
pub fn lifetimes ( & self ) -> impl Iterator < Item = & LifetimeParam > {
108
- struct Lifetimes < ' a > ( Iter < ' a , GenericParam > ) ;
109
-
110
- impl < ' a > Iterator for Lifetimes < ' a > {
111
- type Item = & ' a LifetimeParam ;
112
-
113
- fn next ( & mut self ) -> Option < Self :: Item > {
114
- let next = match self . 0 . next ( ) {
115
- Some ( item) => item,
116
- None => return None ,
117
- } ;
118
- if let GenericParam :: Lifetime ( lifetime) = next {
119
- Some ( lifetime)
120
- } else {
121
- self . next ( )
122
- }
123
- }
124
- }
125
-
126
108
Lifetimes ( self . params . iter ( ) )
127
109
}
128
110
129
111
/// Iterator over the lifetime parameters in `self.params`.
130
112
pub fn lifetimes_mut ( & mut self ) -> impl Iterator < Item = & mut LifetimeParam > {
131
- struct LifetimesMut < ' a > ( IterMut < ' a , GenericParam > ) ;
132
-
133
- impl < ' a > Iterator for LifetimesMut < ' a > {
134
- type Item = & ' a mut LifetimeParam ;
135
-
136
- fn next ( & mut self ) -> Option < Self :: Item > {
137
- let next = match self . 0 . next ( ) {
138
- Some ( item) => item,
139
- None => return None ,
140
- } ;
141
- if let GenericParam :: Lifetime ( lifetime) = next {
142
- Some ( lifetime)
143
- } else {
144
- self . next ( )
145
- }
146
- }
147
- }
148
-
149
113
LifetimesMut ( self . params . iter_mut ( ) )
150
114
}
151
115
152
116
/// Iterator over the type parameters in `self.params`.
153
117
pub fn type_params ( & self ) -> impl Iterator < Item = & TypeParam > {
154
- struct TypeParams < ' a > ( Iter < ' a , GenericParam > ) ;
155
-
156
- impl < ' a > Iterator for TypeParams < ' a > {
157
- type Item = & ' a TypeParam ;
158
-
159
- fn next ( & mut self ) -> Option < Self :: Item > {
160
- let next = match self . 0 . next ( ) {
161
- Some ( item) => item,
162
- None => return None ,
163
- } ;
164
- if let GenericParam :: Type ( type_param) = next {
165
- Some ( type_param)
166
- } else {
167
- self . next ( )
168
- }
169
- }
170
- }
171
-
172
118
TypeParams ( self . params . iter ( ) )
173
119
}
174
120
175
121
/// Iterator over the type parameters in `self.params`.
176
122
pub fn type_params_mut ( & mut self ) -> impl Iterator < Item = & mut TypeParam > {
177
- struct TypeParamsMut < ' a > ( IterMut < ' a , GenericParam > ) ;
178
-
179
- impl < ' a > Iterator for TypeParamsMut < ' a > {
180
- type Item = & ' a mut TypeParam ;
181
-
182
- fn next ( & mut self ) -> Option < Self :: Item > {
183
- let next = match self . 0 . next ( ) {
184
- Some ( item) => item,
185
- None => return None ,
186
- } ;
187
- if let GenericParam :: Type ( type_param) = next {
188
- Some ( type_param)
189
- } else {
190
- self . next ( )
191
- }
192
- }
193
- }
194
-
195
123
TypeParamsMut ( self . params . iter_mut ( ) )
196
124
}
197
125
198
126
/// Iterator over the constant parameters in `self.params`.
199
127
pub fn const_params ( & self ) -> impl Iterator < Item = & ConstParam > {
200
- struct ConstParams < ' a > ( Iter < ' a , GenericParam > ) ;
201
-
202
- impl < ' a > Iterator for ConstParams < ' a > {
203
- type Item = & ' a ConstParam ;
204
-
205
- fn next ( & mut self ) -> Option < Self :: Item > {
206
- let next = match self . 0 . next ( ) {
207
- Some ( item) => item,
208
- None => return None ,
209
- } ;
210
- if let GenericParam :: Const ( const_param) = next {
211
- Some ( const_param)
212
- } else {
213
- self . next ( )
214
- }
215
- }
216
- }
217
-
218
128
ConstParams ( self . params . iter ( ) )
219
129
}
220
130
221
131
/// Iterator over the constant parameters in `self.params`.
222
132
pub fn const_params_mut ( & mut self ) -> impl Iterator < Item = & mut ConstParam > {
223
- struct ConstParamsMut < ' a > ( IterMut < ' a , GenericParam > ) ;
224
-
225
- impl < ' a > Iterator for ConstParamsMut < ' a > {
226
- type Item = & ' a mut ConstParam ;
227
-
228
- fn next ( & mut self ) -> Option < Self :: Item > {
229
- let next = match self . 0 . next ( ) {
230
- Some ( item) => item,
231
- None => return None ,
232
- } ;
233
- if let GenericParam :: Const ( const_param) = next {
234
- Some ( const_param)
235
- } else {
236
- self . next ( )
237
- }
238
- }
239
- }
240
-
241
133
ConstParamsMut ( self . params . iter_mut ( ) )
242
134
}
243
135
@@ -278,6 +170,114 @@ impl Generics {
278
170
}
279
171
}
280
172
173
+ pub struct Lifetimes < ' a > ( Iter < ' a , GenericParam > ) ;
174
+
175
+ impl < ' a > Iterator for Lifetimes < ' a > {
176
+ type Item = & ' a LifetimeParam ;
177
+
178
+ fn next ( & mut self ) -> Option < Self :: Item > {
179
+ let next = match self . 0 . next ( ) {
180
+ Some ( item) => item,
181
+ None => return None ,
182
+ } ;
183
+ if let GenericParam :: Lifetime ( lifetime) = next {
184
+ Some ( lifetime)
185
+ } else {
186
+ self . next ( )
187
+ }
188
+ }
189
+ }
190
+
191
+ pub struct LifetimesMut < ' a > ( IterMut < ' a , GenericParam > ) ;
192
+
193
+ impl < ' a > Iterator for LifetimesMut < ' a > {
194
+ type Item = & ' a mut LifetimeParam ;
195
+
196
+ fn next ( & mut self ) -> Option < Self :: Item > {
197
+ let next = match self . 0 . next ( ) {
198
+ Some ( item) => item,
199
+ None => return None ,
200
+ } ;
201
+ if let GenericParam :: Lifetime ( lifetime) = next {
202
+ Some ( lifetime)
203
+ } else {
204
+ self . next ( )
205
+ }
206
+ }
207
+ }
208
+
209
+ pub struct TypeParams < ' a > ( Iter < ' a , GenericParam > ) ;
210
+
211
+ impl < ' a > Iterator for TypeParams < ' a > {
212
+ type Item = & ' a TypeParam ;
213
+
214
+ fn next ( & mut self ) -> Option < Self :: Item > {
215
+ let next = match self . 0 . next ( ) {
216
+ Some ( item) => item,
217
+ None => return None ,
218
+ } ;
219
+ if let GenericParam :: Type ( type_param) = next {
220
+ Some ( type_param)
221
+ } else {
222
+ self . next ( )
223
+ }
224
+ }
225
+ }
226
+
227
+ pub struct TypeParamsMut < ' a > ( IterMut < ' a , GenericParam > ) ;
228
+
229
+ impl < ' a > Iterator for TypeParamsMut < ' a > {
230
+ type Item = & ' a mut TypeParam ;
231
+
232
+ fn next ( & mut self ) -> Option < Self :: Item > {
233
+ let next = match self . 0 . next ( ) {
234
+ Some ( item) => item,
235
+ None => return None ,
236
+ } ;
237
+ if let GenericParam :: Type ( type_param) = next {
238
+ Some ( type_param)
239
+ } else {
240
+ self . next ( )
241
+ }
242
+ }
243
+ }
244
+
245
+ pub struct ConstParams < ' a > ( Iter < ' a , GenericParam > ) ;
246
+
247
+ impl < ' a > Iterator for ConstParams < ' a > {
248
+ type Item = & ' a ConstParam ;
249
+
250
+ fn next ( & mut self ) -> Option < Self :: Item > {
251
+ let next = match self . 0 . next ( ) {
252
+ Some ( item) => item,
253
+ None => return None ,
254
+ } ;
255
+ if let GenericParam :: Const ( const_param) = next {
256
+ Some ( const_param)
257
+ } else {
258
+ self . next ( )
259
+ }
260
+ }
261
+ }
262
+
263
+ pub struct ConstParamsMut < ' a > ( IterMut < ' a , GenericParam > ) ;
264
+
265
+ impl < ' a > Iterator for ConstParamsMut < ' a > {
266
+ type Item = & ' a mut ConstParam ;
267
+
268
+ fn next ( & mut self ) -> Option < Self :: Item > {
269
+ let next = match self . 0 . next ( ) {
270
+ Some ( item) => item,
271
+ None => return None ,
272
+ } ;
273
+ if let GenericParam :: Const ( const_param) = next {
274
+ Some ( const_param)
275
+ } else {
276
+ self . next ( )
277
+ }
278
+ }
279
+ }
280
+
281
281
/// Returned by `Generics::split_for_impl`.
282
282
#[ cfg( feature = "printing" ) ]
283
283
#[ cfg_attr(
0 commit comments