connection_string/
utils.rs

1// Return early with an error if a condition is not satisfied.
2#[doc(hidden)]
3#[macro_export]
4macro_rules! ensure {
5    ($cond:expr, $msg:literal) => {
6        if !$cond {
7            return Err($crate::Error::new($msg.into()));
8        };
9    };
10
11    ($cond:expr, $msg:expr) => {
12        if !$cond {
13            return Err($crate::Error::new($msg.into()));
14        };
15    };
16}
17
18// Return early with an error.
19#[doc(hidden)]
20#[macro_export]
21macro_rules! bail {
22    ($msg:literal) => {
23        return Err($crate::Error::new($msg.into()))
24    };
25
26    ($msg:expr) => {
27        return Err($crate::Error::new($msg.into()))
28    };
29
30    ($fmt:expr, $($arg:tt)*) => {
31        return Err($crate::Error::new(&*format!($fmt, $($arg)*)))
32    };
33}