b3_utils

Macro require

source
macro_rules! require {
    ($condition:expr, $($msg:tt)*) => { ... };
}
Expand description

Macro to enforce a condition and return an error if it fails.

ยงExample

use b3_utils::require;

fn example_function(x: u32, y: u32) -> Result<(), String> {
    require!(x < y, "x must be less than y");
    Ok(())
}

assert_eq!(example_function(1, 2), Ok(()));
assert_eq!(example_function(2, 1), Err("x must be less than y".to_string()));