Skip to content

Commit

Permalink
Rollup merge of rust-lang#126047 - cuviper:installer-try_for_each, r=…
Browse files Browse the repository at this point in the history
…albertlarsan68

Simplify the rayon calls in the installer

Rayon's `try_for_each` makes the `CombinedEncoder` a lot simpler.
  • Loading branch information
matthiaskrgr authored Jun 7, 2024
2 parents 072e800 + c0e2543 commit d736b83
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/tools/rust-installer/src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,16 @@ impl Write for CombinedEncoder {
}

fn write_all(&mut self, buf: &[u8]) -> std::io::Result<()> {
self.encoders
.par_iter_mut()
.map(|w| w.write_all(buf))
.collect::<std::io::Result<Vec<()>>>()?;
Ok(())
self.encoders.par_iter_mut().try_for_each(|w| w.write_all(buf))
}

fn flush(&mut self) -> std::io::Result<()> {
self.encoders.par_iter_mut().map(|w| w.flush()).collect::<std::io::Result<Vec<()>>>()?;
Ok(())
self.encoders.par_iter_mut().try_for_each(Write::flush)
}
}

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

0 comments on commit d736b83

Please sign in to comment.