Skip to main content

OrFail

Trait OrFail 

Source
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> { ... }

Required Associated Types§

Source

type Output

The success type of the test result.

Required Methods§

Source

fn or_fail(self) -> Result<Self::Output>

Converts a value into a Result containing either the Self::Output type or a [TestAssertionFailure].

The most frequently used implementations convert Result<T, E> into Result<T, TestAssertionFailure> and Option<T> into Result<T, TestAssertionFailure>.

Implementations on Foreign Types§

Source§

impl<T> OrFail for Option<T>

Source§

type Output = T

Source§

fn or_fail(self) -> Result<T, TestAssertionFailure>

Source§

impl<T, E: Debug> OrFail for Result<T, E>

Source§

type Output = T

Source§

fn or_fail(self) -> Result<T, TestAssertionFailure>

Implementors§