1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/// Exits a function early with an `Error`.
#[macro_export]
macro_rules! bail
{
	($($arg:tt)*) => {
		return Err($crate::format_err!($($arg)*).into());
	};
}

/// Exits a function early with an `Error` if the condition is not satisfied.
#[macro_export]
macro_rules! ensure
{
	($cond:expr, $($arg:tt)*) => {
		if !($cond) {
			return Err($crate::format_err!($($arg)*).into());
		}
	};
}

/// Creates an `Error` using the standard string interpolation syntax.
#[macro_export]
macro_rules! format_err
{
	($($arg:tt)*) => { $crate::err_msg(format_args!($($arg)*)) };
}