1
1
use crate :: array;
2
- use crate :: iter:: { FusedIterator , Iterator } ;
2
+ use crate :: iter:: { ByRefSized , FusedIterator , Iterator } ;
3
3
use crate :: ops:: { ControlFlow , NeverShortCircuit , Try } ;
4
4
5
5
/// An iterator over `N` elements of the iterator at a time.
@@ -82,12 +82,12 @@ where
82
82
}
83
83
}
84
84
85
- fn fold < B , F > ( mut self , init : B , mut f : F ) -> B
85
+ fn fold < B , F > ( mut self , init : B , f : F ) -> B
86
86
where
87
87
Self : Sized ,
88
88
F : FnMut ( B , Self :: Item ) -> B ,
89
89
{
90
- self . try_fold ( init, |acc , x| NeverShortCircuit ( f ( acc , x ) ) ) . 0
90
+ self . try_fold ( init, NeverShortCircuit :: wrap_mut_2 ( f ) ) . 0
91
91
}
92
92
}
93
93
@@ -111,25 +111,27 @@ where
111
111
self . next_back_remainder ( ) ;
112
112
113
113
let mut acc = init;
114
- let mut iter = self . iter . by_ref ( ) . rev ( ) ;
114
+ let mut iter = ByRefSized ( & mut self . iter ) . rev ( ) ;
115
115
116
116
// NB remainder is handled by `next_back_remainder`, so
117
117
// `next_chunk` can't return `Err` with non-empty remainder
118
118
// (assuming correct `I as ExactSizeIterator` impl).
119
119
while let Ok ( mut chunk) = iter. next_chunk ( ) {
120
+ // FIXME: do not do double reverse
121
+ // (we could instead add `next_chunk_back` for example)
120
122
chunk. reverse ( ) ;
121
123
acc = f ( acc, chunk) ?
122
124
}
123
125
124
126
try { acc }
125
127
}
126
128
127
- fn rfold < B , F > ( mut self , init : B , mut f : F ) -> B
129
+ fn rfold < B , F > ( mut self , init : B , f : F ) -> B
128
130
where
129
131
Self : Sized ,
130
132
F : FnMut ( B , Self :: Item ) -> B ,
131
133
{
132
- self . try_rfold ( init, |acc , x| NeverShortCircuit ( f ( acc , x ) ) ) . 0
134
+ self . try_rfold ( init, NeverShortCircuit :: wrap_mut_2 ( f ) ) . 0
133
135
}
134
136
}
135
137
0 commit comments