diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2023-04-16 19:19:09 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-16 19:19:09 +0000 |
| commit | 55083fb3ccee36c623c91b48ecc7d1f563ed80f8 (patch) | |
| tree | b2166e9a5f93646f7123e2eb323331bf9a4b2fa2 /xtask/src/run/iter.rs | |
| parent | 56bf829931cd3f8267ad435f6ff8f3ae200418b4 (diff) | |
| parent | b7e4498a7136041d89541bdc7725c8c023fa5c9c (diff) | |
Merge #736
736: More `xtasks` and add examples to `rtic` repo r=korken89 a=datdenkikniet
This was in #732 before, but decluttering that PR seemed sensible
Co-authored-by: datdenkikniet <jcdra1@gmail.com>
Diffstat (limited to 'xtask/src/run/iter.rs')
| -rw-r--r-- | xtask/src/run/iter.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/xtask/src/run/iter.rs b/xtask/src/run/iter.rs new file mode 100644 index 0000000..d18ad49 --- /dev/null +++ b/xtask/src/run/iter.rs @@ -0,0 +1,48 @@ +use super::FinalRunResult; + +pub use iter::*; + +pub trait CoalescingRunner<'c> { + /// Run all the commands in this iterator, and coalesce the results into + /// one error (if any individual commands failed) + fn run_and_coalesce(self) -> Vec<FinalRunResult<'c>>; +} + +#[cfg(not(feature = "rayon"))] +mod iter { + use super::*; + use crate::{argument_parsing::Globals, cargo_command::*, run::run_and_convert}; + + pub fn into_iter<T: IntoIterator>(var: T) -> impl Iterator<Item = T::Item> { + var.into_iter() + } + + impl<'g, 'c, I> CoalescingRunner<'c> for I + where + I: Iterator<Item = (&'g Globals, CargoCommand<'c>, bool)>, + { + fn run_and_coalesce(self) -> Vec<FinalRunResult<'c>> { + self.map(run_and_convert).collect() + } + } +} + +#[cfg(feature = "rayon")] +mod iter { + use super::*; + use crate::{argument_parsing::Globals, cargo_command::*, run::run_and_convert}; + use rayon::prelude::*; + + pub fn into_iter<T: IntoParallelIterator>(var: T) -> impl ParallelIterator<Item = T::Item> { + var.into_par_iter() + } + + impl<'g, 'c, I> CoalescingRunner<'c> for I + where + I: ParallelIterator<Item = (&'g Globals, CargoCommand<'c>, bool)>, + { + fn run_and_coalesce(self) -> Vec<FinalRunResult<'c>> { + self.map(run_and_convert).collect() + } + } +} |
