pub struct LoopGuard {
    pub max_ticks: i32,
    pub count: i32,
}
Expand description

Utility for preventing infinite loops

Use as a guard rail inside a loop or while block

Meant to be used as a development dependency

Fields

max_ticks: i32count: i32

Implementations

Create a new LoopGuard

Make sure to create the LoopGuard instance outside the loop block

Arguments
  • max_ticks - The limit of how many times a loop should run
use loop_guard::LoopGuard;

let mut guard = LoopGuard::new(10);

loop {
    guard.protect() // This panic after 10 loops
}

From within a while or loop block, panic if the loop iteration surpasses the LoopGuard’s max_ticks value.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.