macro_rules! assert_err {
($cond:expr $(,)?) => { ... };
($cond:expr, $($arg:tt)+) => { ... };
}
Expand description
Asserts that the expression matches an Err(_)
variant, returning the contained value.
§Uses
Assertions are always checked in both debug and release builds, and cannot be disabled.
See debug_assert_err!
for assertions that are not enabled in release builds by default.
§Custom messages
This macro has a second form, where a custom panic message can be provided
with or without arguments for formatting. See std::fmt
for syntax for this form.
§Examples
let res: Result<i32, ()> = Err(());
assert_err!(res);
// With a custom message.
assert_err!(res, "we are checking if there was an error with {:?}", res);
An Ok(_)
variant will panic:
ⓘ
let res: Result<i32, ()> = Ok(42);
assert_err!(res); // Will panic