Skip to main content

ResultExpectations

Trait ResultExpectations 

Source
pub trait ResultExpectations<'e, T, E>
where T: Debug, E: Debug,
{ // Required methods fn to_be_ok(self) -> Self; fn to_be_err(self) -> Self; fn to_be_ok_matching<F>(self, predicate: F) -> Self where F: Fn(&T) -> bool + 'e; fn to_be_err_matching<F>(self, predicate: F) -> Self where F: Fn(&E) -> bool + 'e; }
Expand description

Extension trait for Result expectations

Required Methods§

Source

fn to_be_ok(self) -> Self

Expect the Result to be Ok


let result: Result<i32, &str> = Ok(42);
expect(result).to_be_ok();

asserts that the Result is Ok

Source

fn to_be_err(self) -> Self

Expect the Result to be Err


let result: Result<i32, &str> = Err("error");
expect(result).to_be_err();

asserts that the Result is Err

Source

fn to_be_ok_matching<F>(self, predicate: F) -> Self
where F: Fn(&T) -> bool + 'e,

Expect the Result to be Ok and the Ok value to match a predicate


let result: Result<i32, &str> = Ok(42);
expect(result).to_be_ok_matching(|v| *v > 40);

asserts that the Result is Ok and the predicate returns true when applied to the Ok value

Source

fn to_be_err_matching<F>(self, predicate: F) -> Self
where F: Fn(&E) -> bool + 'e,

Expect the Result to be Err and the Err value to match a predicate


let result: Result<i32, &str> = Err("error");
expect(result).to_be_err_matching(|e| *e == "error");

asserts that the Result is Err and the predicate returns true when applied to the Err value

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.

Implementors§

Source§

impl<'e, T, E, B> ResultExpectations<'e, T, E> for B
where T: Debug + 'e, E: Debug + 'e, B: ExpectationBuilder<'e, Value = Result<T, E>>,