assertables

Macro assert_some_as_result

source
macro_rules! assert_some_as_result {
    ($a:expr $(,)?) => { ... };
}
Expand description

Assert an expression.is_some() is true.

Pseudocode:
a is Some(_)

  • If true, return Result Ok(()).

  • Otherwise, return Result Err with a diagnostic message.

This macro provides the same statements as assert_some, except this macro returns a Result, rather than doing a panic.

This macro is useful for runtime checks, such as checking parameters, or sanitizing inputs, or handling different results in different ways.

ยงModule macros