Skip to content

Commit c0e2543

Browse files
committed
Simplify the rayon calls in the installer
Rayon's `try_for_each` makes the `CombinedEncoder` a lot simpler.
1 parent db8aca4 commit c0e2543

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

Diff for: src/tools/rust-installer/src/compression.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -214,22 +214,16 @@ impl Write for CombinedEncoder {
214214
}
215215

216216
fn write_all(&mut self, buf: &[u8]) -> std::io::Result<()> {
217-
self.encoders
218-
.par_iter_mut()
219-
.map(|w| w.write_all(buf))
220-
.collect::<std::io::Result<Vec<()>>>()?;
221-
Ok(())
217+
self.encoders.par_iter_mut().try_for_each(|w| w.write_all(buf))
222218
}
223219

224220
fn flush(&mut self) -> std::io::Result<()> {
225-
self.encoders.par_iter_mut().map(|w| w.flush()).collect::<std::io::Result<Vec<()>>>()?;
226-
Ok(())
221+
self.encoders.par_iter_mut().try_for_each(Write::flush)
227222
}
228223
}
229224

230225
impl Encoder for CombinedEncoder {
231226
fn finish(self: Box<Self>) -> Result<(), Error> {
232-
self.encoders.into_par_iter().map(|e| e.finish()).collect::<Result<Vec<()>, Error>>()?;
233-
Ok(())
227+
self.encoders.into_par_iter().try_for_each(Encoder::finish)
234228
}
235229
}

0 commit comments

Comments
 (0)