Skip to main content

or_return

Macro or_return 

Source
macro_rules! or_return {
    ($expr:expr) => { ... };
    ($expr:expr, $ret:expr) => { ... };
}
Expand description

Unwraps an Option, returning from the enclosing function if it’s None — collapses the let Some(x) = expr else { return }; pattern that shows up constantly in systems (which return (), so the ? operator isn’t an option the way it would be in a function returning Option/Result).

let material = or_return!(materials.get(handle));
let material = or_return!(materials.get(handle), return None); // custom return value