pub trait AssertOkExt {
// Required methods
fn assert_ok(self) -> Self;
fn debug_assert_ok(self) -> Self;
}Expand description
An extension trait to add the assertion_ok methods.
Required Methods§
Sourcefn assert_ok(self) -> Self
fn assert_ok(self) -> Self
§Panics
The method panics if it is Err and passthrough feature is disabled.
Otherwise, the method return self as is.
§Examples
use chain_assertions::prelude::*;
let x: Result<i32, &str> = Ok(21);
let x = x.assert_ok().map(|x| x * 2);
assert_eq!(x, Ok(42));ⓘ
use chain_assertions::prelude::*;
let x: Result<i32, &str> = Err("oops");
let _ = x.assert_ok().map(|x| x * 2);
// ^-- panics hereSourcefn debug_assert_ok(self) -> Self
fn debug_assert_ok(self) -> Self
Asserts the Result is Ok but check only in debug builds.
§Panics
The method panics if all following conditions are satisfied:
- It is
Err debug_assertionsis enabledpassthroughfeature is disabled
Otherwise, the method returns self as is.
§Examples
use chain_assertions::prelude::*;
let x: Result<i32, &str> = Ok(21);
let x = x.debug_assert_ok().map(|x| x * 2);
assert_eq!(x, Ok(42));Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.