Macro etrace::ok_or [−][src]
macro_rules! ok_or { ($code:expr, $err:ident, $or:expr) => { ... }; ($code:expr, $or:expr) => { ... }; }
Runs $code
and returns either the unwrapped result or binds the error to $err
and executes
$or
(or can then access the error using the identifier passed as $err
)
Example:
// This code either prints the error and exits (if error) or prints the result (if ok) let unwrapped = ok_or!(result, example_error_identifier, { eprintln!("Fatal error: \"{}\"", example_error_identifier); std::process::exit(1); }); println!("Result: \"{}\"", unwrapped);