1 /// Exits a function early with an `Error`.
3 /// The `bail!` macro provides an easy way to exit a function. `bail!(X)` is
4 /// equivalent to writing:
7 /// return Err(format_err!(X))
12 return Err($
crate::err_msg($e
));
14 ($fmt
:expr
, $
($arg
:tt
)*) => {
15 return Err($
crate::err_msg(format
!($fmt
, $
($arg
)*)));
19 /// Exits a function early with an `Error` if the condition is not satisfied.
21 /// Similar to `assert!`, `ensure!` takes a condition and exits the function
22 /// if the condition fails. Unlike `assert!`, `ensure!` returns an `Error`,
23 /// it does not panic.
24 #[macro_export(local_inner_macros)]
26 ($cond
:expr
, $e
:expr
) => {
31 ($cond
:expr
, $fmt
:expr
, $
($arg
:tt
)*) => {
33 bail
!($fmt
, $
($arg
)*);
38 /// Constructs an `Error` using the standard string interpolation syntax.
41 /// #[macro_use] extern crate failure;
45 /// let err = format_err!("Error code: {}", code);
49 macro_rules
! format_err
{
50 ($
($arg
:tt
)*) => { $crate::err_msg(format!($($arg)*)) }