macro_rules! ensure {
($cond:expr, $err:expr) => { ... };
}Expand description
Ensure a condition is true, otherwise return an error.
ยงExample
use dbrest::ensure;
use dbrest::Error;
fn validate(x: i32) -> Result<(), Error> {
ensure!(x >= 0, Error::InvalidQueryParam {
param: "x".to_string(),
message: "must be non-negative".to_string(),
});
Ok(())
}