Macro bail

Source
macro_rules! bail {
    (
        $fmt:literal $(, $arg:expr)*
        $(; label_message: $label_message:literal $(, $label_message_arg:expr)*)?
        $(; label: $label:expr)*
        $(; note: $note:literal $(, $note_arg:expr)*)*
        $(; hint: $hint:literal $(, $hint_arg:expr)*)*
        $(; code: $code:expr)?
        $(,)?
    ) => { ... };
    ($error:expr) => { ... };
    ($($tts:tt)*) => { ... };
}
Expand description

Early-return with a StrResult or SourceResult.

If called with just a string and format args, returns with a StrResult. If called with a span, a string and format args, returns a SourceResult.

You can also emit hints with the ; hint: "..." syntax.

bail!("bailing with a {}", "string result");
bail!(span, "bailing with a {}", "source result");
bail!(
    span, "bailing with a {}", "source result";
    hint: "hint 1"
);
bail!(
    span, "bailing with a {}", "source result";
    hint: "hint 1";
    hint: "hint 2";
);