Macro claim::assert_ok_eq
source · [−]macro_rules! assert_ok_eq {
($cond:expr, $expected:expr,) => { ... };
($cond:expr, $expected:expr) => { ... };
($cond:expr, $expected:expr, $($arg:tt)+) => { ... };
}
Expand description
Asserts that expression returns Ok(T)
variant
and its value of T
type equals to 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 custom messages
assert_ok_eq!(res, 1, "Everything is good with {:?}", res);
Value of T
type from Ok(T)
will be returned from the macro call:
let res: Result<i32, ()> = Ok(1);
let value = assert_ok_eq!(res, 1);
assert_eq!(value, 1);
Err(..)
variant will cause panic:
ⓘ
let res: Result<i32, ()> = Err(());
assert_ok_eq!(res, 1); // Will panic