pub trait OrFailExt<T> {
// Required method
fn or_fail(self) -> TestResult<T>;
}Expand description
Provides an extension method for converting an arbitrary type into a
Result.
A type can implement this trait to provide an easy way to return immediately
from a test in conjunction with the ? operator. This is useful for
Result types whose Result::Err variant does not implement
std::error::Error.
There is an implementation of this trait for anyhow::Error (which does
not implement std::error::Error) when the anyhow feature is enabled.
Importing this trait allows one to easily map anyhow::Error to a test
failure:
#[test]
fn should_work() -> Result<()> {
let value = something_which_can_fail().or_fail()?;
...
}
fn something_which_can_fail() -> anyhow::Result<...> { ... }Required Methods§
Sourcefn or_fail(self) -> TestResult<T>
fn or_fail(self) -> TestResult<T>
Converts this instance into a Result.
Typically, the Self type is itself a core::result::Result. This
method should then map the Err variant to a [TestAssertionFailure]
and leave the Ok variant unchanged.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<OkT, CaseT: Debug> OrFailExt<OkT> for Result<OkT, TestError<CaseT>>
Available on crate feature proptest only.
impl<OkT, CaseT: Debug> OrFailExt<OkT> for Result<OkT, TestError<CaseT>>
proptest only.