easy_error/
macros.rs

1/// Exits a function early with an `Error`.
2#[macro_export]
3macro_rules! bail
4{
5	($($arg:tt)*) => {
6		return Err($crate::format_err!($($arg)*).into());
7	};
8}
9
10/// Exits a function early with an `Error` if the condition is not satisfied.
11#[macro_export]
12macro_rules! ensure
13{
14	($cond:expr, $($arg:tt)*) => {
15		if !($cond) {
16			return Err($crate::format_err!($($arg)*).into());
17		}
18	};
19}
20
21/// Creates an `Error` using the standard string interpolation syntax.
22#[macro_export]
23macro_rules! format_err
24{
25	($($arg:tt)*) => { $crate::err_msg(format_args!($($arg)*)) };
26}