check

Macro check 

Source
macro_rules! check {
    ($cond:expr $(,)?) => { ... };
    ($cond:expr, $e: expr $(,)?) => { ... };
}
Expand description

Exits the function prematurely if the condition is not met.

ยงExamples

use check::check;

fn foo(a: i32, n: i32) -> Option<()> {
    check!(a < n);
    // If the code reaches this line, then you know that `a < n`.
    // If it was not true, `None` was returned.
    Some(())
}
use check::check;

enum MyError {
    TooBig,
    NotEqual,
}

fn foo(a: i32, n: i32) -> Result<(), MyError> {
    check!(a < n, MyError::TooBig);
    // If the code reaches this line, then you know that `a < n`.
    // If it was not true, `Err(MyError::TooBig)` was returned.
    Ok(())
}