pub trait AssertErrExt {
// Required methods
fn assert_err(self) -> Self;
fn debug_assert_err(self) -> Self;
}Expand description
An extension trait to add the assertion_err methods.
Required Methods§
Sourcefn assert_err(self) -> Self
fn assert_err(self) -> Self
§Panics
The method panics if it is Ok and passthrough feature 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().map_err(|x| x * 2);
assert_eq!(x, Err(42));ⓘ
use chain_assertions::prelude::*;
let x: Result<&str, i32> = Ok("success");
let x = x.assert_err().map_err(|x| x * 2);
// ^-- panics hereSourcefn debug_assert_err(self) -> Self
fn debug_assert_err(self) -> Self
Asserts the Result is Err but check only in debug builds.
§Panics
The method panics if all following conditions are satisfied:
- It is
Err. debug_assertionsis enabled.passthroughfeature is disabled.
Otherwise, the method returns self as is.
§Examples
use chain_assertions::prelude::*;
let x: Result<&str, i32> = Err(21);
let x = x.debug_assert_err().map_err(|x| x * 2);
assert_eq!(x, Err(42), "Expected Err(42)");ⓘ
use chain_assertions::prelude::*;
let x: Result<&str, i32> = Ok("success");
let _ = x.debug_assert_err();
// ^-- panics here only in debug builds
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.