pub trait AssertErrAndExt<T, E> {
// Required methods
fn assert_err_and(self, cond: impl FnOnce(&E) -> bool) -> Self;
fn debug_assert_err_and(self, cond: impl FnOnce(&E) -> bool) -> Self;
}Required Methods§
Sourcefn assert_err_and(self, cond: impl FnOnce(&E) -> bool) -> Self
fn assert_err_and(self, cond: impl FnOnce(&E) -> bool) -> Self
Asserts the Result is Err and satisfies the condition.
§Panics
The method panics if all following conditions are satisfied:
- It is
Ok, orErrbut user-provided condition returnsfalse debug_assertionsis enabledpassthroughfeature is disabled
Otherwise, the method return self as is.
§Examples
use chain_assertions::prelude::*;
let x: Result<&str, i32> = Err(21);
let x = x.assert_err_and(|x| x == &21).map_err(|x| x * 2);ⓘ
use chain_assertions::prelude::*;
let x: Result<&str, i32> = Ok("debuggable");
let x = x.assert_err_and(|x| x == &42).map_err(|x| x + 1);
// ^-- panics hereSourcefn debug_assert_err_and(self, cond: impl FnOnce(&E) -> bool) -> Self
fn debug_assert_err_and(self, cond: impl FnOnce(&E) -> bool) -> Self
Asserts the Result is Err and satisfies the condition only in debug builds.
§Panics
The method panics if all following conditions are satisfied:
- It is
Ok, orErrbut user-provided condition returnsfalse debug_assertionsis enabledpassthroughfeature is disabled
Otherwise, the method return self as is.
§Examples
use chain_assertions::prelude::*;
let x: Result<&str, i32> = Err(21);
let x = x.debug_assert_err_and(|x| x == &21).map_err(|x| x * 2);
assert_eq!(x, Err(42), "Expected Err(42)");ⓘ
use chain_assertions::prelude::*;
let x: Result<&str, i32> = Ok("debuggable");
let x = x.debug_assert_err_and(|x| x == &42).map_err(|x| x + 1);
// ^-- panics here only in debug buildsDyn 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.