[][src]Macro http_types::ensure

macro_rules! ensure {
    ($cond:expr, $msg:literal $(,)?) => { ... };
    ($cond:expr, $err:expr $(,)?) => { ... };
    ($cond:expr, $fmt:expr, $($arg:tt)*) => { ... };
}

Return early with an error if a condition is not satisfied.

This macro is equivalent to if !$cond { return Err(From::from($err)); }.

Analogously to assert!, ensure! takes a condition and exits the function if the condition fails. Unlike assert!, ensure! returns an Error rather than panicking.