macro_rules! assert_err_eq {
($cond:expr, $expected:expr $(,)?) => { ... };
($cond:expr, $expected:expr, $($arg:tt)+) => { ... };
}
Expand description
Asserts that the left expression contains an Err(E)
variant and its contained value of type
E
equals the right expression.
§Uses
Assertions are always checked in both debug and release builds, and cannot be disabled. See
debug_assert_err_eq!
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(1);
assert_err_eq!(res, 1);
// With a custom message
assert_err_eq!(res, 1, "Everything is good with {:?}", res);
The contained value will be returned from the macro call:
let res: Result<(), i32> = Err(1);
let value = assert_err_eq!(res, 1);
assert_eq!(value, 1);
An Ok(_)
variant will panic:
ⓘ
let res: Result<(), i32> = Ok(());
assert_err_eq!(res, 1); // Will panic