pub trait AssertOkAndExt<T> {
// Required methods
fn assert_ok_and(self, cond: impl FnOnce(&T) -> bool) -> Self;
fn debug_assert_ok_and(self, cond: impl FnOnce(&T) -> bool) -> Self;
}Expand description
An extension trait to add the assertion_ok_and methods.
Required Methods§
Sourcefn assert_ok_and(self, cond: impl FnOnce(&T) -> bool) -> Self
fn assert_ok_and(self, cond: impl FnOnce(&T) -> bool) -> Self
Asserts the Result is Ok and satisfies the condition.
§Panics
The method panics if all following conditions are satisfied:
- It is
Err, orOkbut user-provided condition returnsfalse debug_assertionsis enabledpassthroughfeature 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_and(|x| x == &21).map(|x| x * 2);
assert_eq!(x, Ok(42), "Expected Ok(42)");Sourcefn debug_assert_ok_and(self, cond: impl FnOnce(&T) -> bool) -> Self
fn debug_assert_ok_and(self, cond: impl FnOnce(&T) -> bool) -> Self
Asserts the Result is Ok and satisfies the condition only in debug builds.
§Panics
The method panics if all following conditions are satisfied:
- It is
Err, orOkbut user-provided condition returnsfalse debug_assertionsis enabledpassthroughfeature is disabled
Otherwise, the method return self as is.
§Examples
use chain_assertions::prelude::*;
let x: Result<i32, &str> = Ok(21);
let x = x.debug_assert_ok_and(|x| x == &21).map(|x| x * 2);
assert_eq!(x, Ok(42), "Expected 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.