Skip to main content

bb

Macro bb 

Source
bb!() { /* proc-macro */ }
Expand description

Behaves like the ? operator, unwrapping a Result or Option but will break out of a scope labeled with the 'block label if a None or Err is encountered. This can be used to achieve something that resembles try-catch.

use break_block_macro::bb;

let result = 'block: {
    let one = bb!(Ok("one"));
    assert_eq!(one, "one");

    let _two = bb!(Err("two"));
    Ok("three")
};
assert_eq!(result, Err("two"));