Skip to content

Commit

Permalink
fix: Replace while loop with for loop for Clippy
Browse files Browse the repository at this point in the history
Clippy flagged the prior version of the loop, and this change satisfies
Clippy.

Signed-off-by: Andrew Lilley Brinker <[email protected]>
  • Loading branch information
alilleybrinker committed Feb 29, 2024
1 parent 739f997 commit 85a21bf
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions xtask/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ where
It: Iterator<Item = DynStep<'step>>,
I: IntoIterator<Item = DynStep<'step>, IntoIter = It>,
{
fn inner<'step>(
mut steps: impl Iterator<Item = DynStep<'step>>,
) -> Result<()> {
let mut forward_error = None;
fn inner<'step>(steps: impl Iterator<Item = DynStep<'step>>) -> Result<()> {
let mut forward_err = None;
let mut completed_steps = Vec::new();

// Run the steps forward.
while let Some(step) = steps.next() {
for step in steps {
if let Err(forward) = forward(step) {
forward_error = Some(forward);
forward_err = Some(forward);
completed_steps.push(step);
break;
}
Expand All @@ -38,16 +36,14 @@ where
}

// If forward had an error, initiate rollback.
if let Some(forward) = forward_error {
let mut steps = completed_steps.into_iter();

while let Some(reverse_step) = steps.next() {
if let Err(backward) = backward(reverse_step) {
bail!(PipelineError::rollback(forward, backward));
if let Some(forward_err) = forward_err {
for step in completed_steps {
if let Err(backward_err) = backward(step) {
bail!(PipelineError::rollback(forward_err, backward_err));
}
}

bail!(PipelineError::forward(forward));
bail!(PipelineError::forward(forward_err));
}

Ok(())
Expand Down

0 comments on commit 85a21bf

Please sign in to comment.