mac

Macro unwrap_or_return

source
macro_rules! unwrap_or_return {
    ($e:expr, $r:expr) => { ... };
}
Expand description

Unwraps an Option or returns from the function with the specified return value.

Can be used on Results by first calling .ok() or .err() on them.

ยงExamples

fn take_pair<I:Iterator>(iter: &mut I) -> Option<(<I as Iterator>::Item, <I as Iterator>::Item)> {
   let first = unwrap_or_return!(iter.next(), None);
   Some((first, unwrap_or_return!(iter.next(), None)))
}