@@ -339,8 +339,13 @@ unsafe impl<'a, I, T: 'a> TrustedLen for Cloned<I>
339
339
#[ must_use = "iterators are lazy and do nothing unless consumed" ]
340
340
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
341
341
pub struct Cycle < I > {
342
- pub ( super ) orig : I ,
343
- pub ( super ) iter : I ,
342
+ orig : I ,
343
+ iter : I ,
344
+ }
345
+ impl < I : Clone > Cycle < I > {
346
+ pub ( super ) fn new ( iter : I ) -> Cycle < I > {
347
+ Cycle { orig : iter. clone ( ) , iter }
348
+ }
344
349
}
345
350
346
351
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -380,9 +385,15 @@ impl<I> FusedIterator for Cycle<I> where I: Clone + Iterator {}
380
385
#[ stable( feature = "iterator_step_by" , since = "1.28.0" ) ]
381
386
#[ derive( Clone , Debug ) ]
382
387
pub struct StepBy < I > {
383
- pub ( super ) iter : I ,
384
- pub ( super ) step : usize ,
385
- pub ( super ) first_take : bool ,
388
+ iter : I ,
389
+ step : usize ,
390
+ first_take : bool ,
391
+ }
392
+ impl < I > StepBy < I > {
393
+ pub ( super ) fn new ( iter : I , step : usize ) -> StepBy < I > {
394
+ assert ! ( step != 0 ) ;
395
+ StepBy { iter, step : step - 1 , first_take : true }
396
+ }
386
397
}
387
398
388
399
#[ stable( feature = "iterator_step_by" , since = "1.28.0" ) ]
@@ -867,8 +878,13 @@ impl<B, I: FusedIterator, F> FusedIterator for FilterMap<I, F>
867
878
#[ must_use = "iterators are lazy and do nothing unless consumed" ]
868
879
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
869
880
pub struct Enumerate < I > {
870
- pub ( super ) iter : I ,
871
- pub ( super ) count : usize ,
881
+ iter : I ,
882
+ count : usize ,
883
+ }
884
+ impl < I > Enumerate < I > {
885
+ pub ( super ) fn new ( iter : I ) -> Enumerate < I > {
886
+ Enumerate { iter, count : 0 }
887
+ }
872
888
}
873
889
874
890
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1028,9 +1044,14 @@ unsafe impl<I> TrustedLen for Enumerate<I>
1028
1044
#[ must_use = "iterators are lazy and do nothing unless consumed" ]
1029
1045
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1030
1046
pub struct Peekable < I : Iterator > {
1031
- pub ( super ) iter : I ,
1047
+ iter : I ,
1032
1048
/// Remember a peeked value, even if it was None.
1033
- pub ( super ) peeked : Option < Option < I :: Item > > ,
1049
+ peeked : Option < Option < I :: Item > > ,
1050
+ }
1051
+ impl < I : Iterator > Peekable < I > {
1052
+ pub ( super ) fn new ( iter : I ) -> Peekable < I > {
1053
+ Peekable { iter, peeked : None }
1054
+ }
1034
1055
}
1035
1056
1036
1057
// Peekable must remember if a None has been seen in the `.peek()` method.
@@ -1180,9 +1201,14 @@ impl<I: Iterator> Peekable<I> {
1180
1201
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1181
1202
#[ derive( Clone ) ]
1182
1203
pub struct SkipWhile < I , P > {
1183
- pub ( super ) iter : I ,
1184
- pub ( super ) flag : bool ,
1185
- pub ( super ) predicate : P ,
1204
+ iter : I ,
1205
+ flag : bool ,
1206
+ predicate : P ,
1207
+ }
1208
+ impl < I , P > SkipWhile < I , P > {
1209
+ pub ( super ) fn new ( iter : I , predicate : P ) -> SkipWhile < I , P > {
1210
+ SkipWhile { iter, flag : false , predicate }
1211
+ }
1186
1212
}
1187
1213
1188
1214
#[ stable( feature = "core_impl_debug" , since = "1.9.0" ) ]
@@ -1263,9 +1289,14 @@ impl<I, P> FusedIterator for SkipWhile<I, P>
1263
1289
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1264
1290
#[ derive( Clone ) ]
1265
1291
pub struct TakeWhile < I , P > {
1266
- pub ( super ) iter : I ,
1267
- pub ( super ) flag : bool ,
1268
- pub ( super ) predicate : P ,
1292
+ iter : I ,
1293
+ flag : bool ,
1294
+ predicate : P ,
1295
+ }
1296
+ impl < I , P > TakeWhile < I , P > {
1297
+ pub ( super ) fn new ( iter : I , predicate : P ) -> TakeWhile < I , P > {
1298
+ TakeWhile { iter, flag : false , predicate }
1299
+ }
1269
1300
}
1270
1301
1271
1302
#[ stable( feature = "core_impl_debug" , since = "1.9.0" ) ]
@@ -1632,8 +1663,13 @@ impl<B, I, St, F> Iterator for Scan<I, St, F> where
1632
1663
#[ must_use = "iterators are lazy and do nothing unless consumed" ]
1633
1664
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1634
1665
pub struct Fuse < I > {
1635
- pub ( super ) iter : I ,
1636
- pub ( super ) done : bool
1666
+ iter : I ,
1667
+ done : bool
1668
+ }
1669
+ impl < I > Fuse < I > {
1670
+ pub ( super ) fn new ( iter : I ) -> Fuse < I > {
1671
+ Fuse { iter, done : false }
1672
+ }
1637
1673
}
1638
1674
1639
1675
#[ stable( feature = "fused" , since = "1.26.0" ) ]
0 commit comments