fehler_more/lib.rs
1pub use fehler::*;
2
3/// Exits a function early with an `Exception`.
4#[macro_export]
5macro_rules! bail {
6 ($e:expr) => {
7 throw!(Exception::new_adhoc($e));
8 };
9 ($fmt:expr, $($arg:tt)+) => {
10 throw!(error!($fmt, $($arg)+));
11 };
12}
13
14/// Exits a function early with an `Exception` if the condition is not satisfied.
15#[macro_export]
16macro_rules! ensure {
17 ($cond:expr, $e:expr) => {
18 if !($cond) {
19 bail!($e);
20 }
21 };
22 ($cond:expr, $fmt:expr, $($arg:tt)+) => {
23 if !($cond) {
24 bail!($fmt, $($arg)+);
25 }
26 };
27}