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