pub trait OrFail {
type Output;
// Required method
fn or_fail(self) -> Result<Self::Output>;
}Expand description
Provides an extension method for converting an arbitrary type into
googletest’s Result type.
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
Option and Result types whose Result::Err
variant does not implement std::error::Error.
If Result::Err implements std::error::Error you can just use the ?
operator directly.
ⓘ
#[test]
fn should_work() -> googletest::Result<()> {
let value = something_which_can_fail().or_fail()?;
let value = something_which_can_fail_with_option().or_fail()?;
...
}
fn something_which_can_fail() -> std::result::Result<T, String> { ... }
fn something_which_can_fail_with_option() -> Option<T> { ... }