Skip to main content

some_or_return

Macro some_or_return 

Source
macro_rules! some_or_return {
    ($option:expr, $error:expr, $err_val:expr) => { ... };
}
Expand description

Handle Option, early-return with custom value if None

Takes a cimpl::Error to set when the option is None.

§Examples

// With Error::Other
let date = some_or_return!(
    NaiveDate::from_ymd_opt(2024, 1, 20),
    Error::Other("Invalid date".to_string()),
    std::ptr::null_mut()
);

// With different error type
let handle = some_or_return!(
    get_handle(id),
    Error::InvalidHandle(id),
    -1
);