Macro claim::assert_ok[][src]

macro_rules! assert_ok {
    ($cond:expr,) => { ... };
    ($cond:expr) => { ... };
    ($cond:expr, $($arg:tt)+) => { ... };
}

Asserts that expression returns Ok(T) variant.

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 custom messages
assert_ok!(res, "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!(res);
assert_eq!(value, 1);

Err(..) variant will cause panic:

let res = Err(());

assert_ok!(res);  // Will panic