connection_string/
utils.rs

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
27
28
29
30
31
32
33
// Return early with an error if a condition is not satisfied.
#[doc(hidden)]
#[macro_export]
macro_rules! ensure {
    ($cond:expr, $msg:literal) => {
        if !$cond {
            return Err($crate::Error::new($msg.into()));
        };
    };

    ($cond:expr, $msg:expr) => {
        if !$cond {
            return Err($crate::Error::new($msg.into()));
        };
    };
}

// Return early with an error.
#[doc(hidden)]
#[macro_export]
macro_rules! bail {
    ($msg:literal) => {
        return Err($crate::Error::new($msg.into()))
    };

    ($msg:expr) => {
        return Err($crate::Error::new($msg.into()))
    };

    ($fmt:expr, $($arg:tt)*) => {
        return Err($crate::Error::new(&*format!($fmt, $($arg)*)))
    };
}