Skip to content

Commit eb6b729

Browse files
committed
address review comments
1 parent 756bd6e commit eb6b729

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

library/core/src/iter/adapters/array_chunks.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::array;
2-
use crate::iter::{FusedIterator, Iterator};
2+
use crate::iter::{ByRefSized, FusedIterator, Iterator};
33
use crate::ops::{ControlFlow, NeverShortCircuit, Try};
44

55
/// An iterator over `N` elements of the iterator at a time.
@@ -82,12 +82,12 @@ where
8282
}
8383
}
8484

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
8686
where
8787
Self: Sized,
8888
F: FnMut(B, Self::Item) -> B,
8989
{
90-
self.try_fold(init, |acc, x| NeverShortCircuit(f(acc, x))).0
90+
self.try_fold(init, NeverShortCircuit::wrap_mut_2(f)).0
9191
}
9292
}
9393

@@ -111,25 +111,27 @@ where
111111
self.next_back_remainder();
112112

113113
let mut acc = init;
114-
let mut iter = self.iter.by_ref().rev();
114+
let mut iter = ByRefSized(&mut self.iter).rev();
115115

116116
// NB remainder is handled by `next_back_remainder`, so
117117
// `next_chunk` can't return `Err` with non-empty remainder
118118
// (assuming correct `I as ExactSizeIterator` impl).
119119
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)
120122
chunk.reverse();
121123
acc = f(acc, chunk)?
122124
}
123125

124126
try { acc }
125127
}
126128

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
128130
where
129131
Self: Sized,
130132
F: FnMut(B, Self::Item) -> B,
131133
{
132-
self.try_rfold(init, |acc, x| NeverShortCircuit(f(acc, x))).0
134+
self.try_rfold(init, NeverShortCircuit::wrap_mut_2(f)).0
133135
}
134136
}
135137

0 commit comments

Comments
 (0)