(
experiment_ids: &[usize],
experiment_descriptions: &[&str],
)
| 64 | reason = "false-positive, try_fold is fail-fast, our implementation is fail-slow" |
| 65 | )] |
| 66 | fn start_experiments( |
| 67 | experiment_ids: &[usize], |
| 68 | experiment_descriptions: &[&str], |
| 69 | ) -> Result<Vec<u64>, Report<[ExperimentError]>> { |
| 70 | let experiments = experiment_ids |
| 71 | .iter() |
| 72 | .map(|exp_id| { |
| 73 | let description = experiment_descriptions.get(*exp_id).ok_or_else(|| { |
| 74 | Report::new(ExperimentError) |
| 75 | .attach(format!("experiment {exp_id} has no valid description")) |
| 76 | })?; |
| 77 | |
| 78 | let experiments = parse_experiment(description) |
| 79 | .attach(format!("experiment {exp_id} could not be parsed")) |
| 80 | .change_context(ExperimentError)?; |
| 81 | |
| 82 | let experiments = experiments |
| 83 | .into_iter() |
| 84 | .map(|(lhs, rhs)| move || lhs * rhs) |
| 85 | .collect::<Vec<_>>(); |
| 86 | |
| 87 | Ok(experiments) |
| 88 | }) |
| 89 | .fold( |
| 90 | Ok(vec![]), |
| 91 | |accum, value: Result<_, Report<ExperimentError>>| match (accum, value) { |
| 92 | (Ok(mut accum), Ok(value)) => { |
| 93 | accum.extend(value); |
| 94 | |
| 95 | Ok(accum) |
| 96 | } |
| 97 | (Ok(_), Err(err)) => Err(err.expand()), |
| 98 | (Err(accum), Ok(_)) => Err(accum), |
| 99 | (Err(mut accum), Err(err)) => { |
| 100 | accum.push(err); |
| 101 | |
| 102 | Err(accum) |
| 103 | } |
| 104 | }, |
| 105 | ) |
| 106 | .attach("unable to set up experiments")?; |
| 107 | |
| 108 | Ok(experiments.iter().map(|experiment| experiment()).collect()) |
| 109 | } |
| 110 | |
| 111 | fn main() -> Result<(), Report<[ExperimentError]>> { |
| 112 | let experiment_ids = &[0, 2, 3]; |
no test coverage detected