macro_rules! assert_ok {
($cond:expr $(,)?) => { ... };
($cond:expr, $($arg:tt)+) => { ... };
}Expand description
Asserts that the expression matches an Ok(_) variant, returning the contained value.
§Uses
Assertions are always checked in both debug and release builds, and cannot be disabled.
See debug_assert_ok! 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!(res);
// With a custom message
assert_ok!(res, "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!(res);
assert_eq!(value, 1);An Err(..) variant will panic:
ⓘ
let res = Err(());
assert_ok!(res); // Will panic