tiny_bail
Bailing is an error-handling pattern that takes the middle path between unwrap and ?:
- Compared to
unwrap: Bail willreturnorcontinueinstead of panicking. - Compared to
?: Bail will log or ignore the error instead of propagating it.
The middle path avoids unwanted panics without the ergonomic challenges of propagating errors with ?.
This crate provides four macro variants:
r!,
rq!,
c!, and
cq!; along with their long-form aliases
or_return!,
or_return_quiet!,
or_continue!, and
or_continue_quiet!, respectively.
use *;
/// Increment the last number of a list, or warn if it's empty.
The macros support bool, Option, and Result types out-of-the-box. This can be extended by implementing
the Success trait for other types.
You can specify a return value as an optional first argument to the macro, or omit it to default to
Default::default()—which even works in functions with no return value.
License
This crate is available under either of MIT or Apache-2.0 at your choice.