macro_rules! ensure { ($predicate:expr, $context_selector:expr $(,)?) => { ... }; }
Expand description
Ensure a condition is true. If it is not, return from the function with an error.
Examples
fn example(user_id: i32) -> AxResult {
ensure!(user_id > 0, ax_err!(InvalidInput));
// After this point, we know that `user_id` is positive.
let user_id = user_id as u32;
Ok(())
}