pub trait ResultExpectations<'e, T, E>{
// 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§
Sourcefn to_be_ok(self) -> Self
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
Sourcefn to_be_err(self) -> Self
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
Sourcefn to_be_ok_matching<F>(self, predicate: F) -> Self
fn to_be_ok_matching<F>(self, predicate: F) -> Self
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
Sourcefn to_be_err_matching<F>(self, predicate: F) -> Self
fn to_be_err_matching<F>(self, predicate: F) -> Self
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.