@@ -339,8 +339,13 @@ unsafe impl<'a, I, T: 'a> TrustedLen for Cloned<I>
339339#[ must_use = "iterators are lazy and do nothing unless consumed" ]
340340#[ stable( feature = "rust1" , since = "1.0.0" ) ]
341341pub 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+ }
344349}
345350
346351#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -380,9 +385,15 @@ impl<I> FusedIterator for Cycle<I> where I: Clone + Iterator {}
380385#[ stable( feature = "iterator_step_by" , since = "1.28.0" ) ]
381386#[ derive( Clone , Debug ) ]
382387pub 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+ }
386397}
387398
388399#[ stable( feature = "iterator_step_by" , since = "1.28.0" ) ]
@@ -867,8 +878,13 @@ impl<B, I: FusedIterator, F> FusedIterator for FilterMap<I, F>
867878#[ must_use = "iterators are lazy and do nothing unless consumed" ]
868879#[ stable( feature = "rust1" , since = "1.0.0" ) ]
869880pub 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+ }
872888}
873889
874890#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1028,9 +1044,14 @@ unsafe impl<I> TrustedLen for Enumerate<I>
10281044#[ must_use = "iterators are lazy and do nothing unless consumed" ]
10291045#[ stable( feature = "rust1" , since = "1.0.0" ) ]
10301046pub struct Peekable < I : Iterator > {
1031- pub ( super ) iter : I ,
1047+ iter : I ,
10321048 /// 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+ }
10341055}
10351056
10361057// Peekable must remember if a None has been seen in the `.peek()` method.
@@ -1180,9 +1201,14 @@ impl<I: Iterator> Peekable<I> {
11801201#[ stable( feature = "rust1" , since = "1.0.0" ) ]
11811202#[ derive( Clone ) ]
11821203pub 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+ }
11861212}
11871213
11881214#[ stable( feature = "core_impl_debug" , since = "1.9.0" ) ]
@@ -1263,9 +1289,14 @@ impl<I, P> FusedIterator for SkipWhile<I, P>
12631289#[ stable( feature = "rust1" , since = "1.0.0" ) ]
12641290#[ derive( Clone ) ]
12651291pub 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+ }
12691300}
12701301
12711302#[ 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
16321663#[ must_use = "iterators are lazy and do nothing unless consumed" ]
16331664#[ stable( feature = "rust1" , since = "1.0.0" ) ]
16341665pub 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+ }
16371673}
16381674
16391675#[ stable( feature = "fused" , since = "1.26.0" ) ]
0 commit comments