pub trait AssertHasValue<E> {
// Required method
fn has_value(self, expected: E) -> Self;
}Expand description
Assert that a subject of some container type holds a value that is equal to the expected one.
This assertion is implemented for the Option type and the Result type.
For Option it compares the value to the expected one if it has some or
fails if it holds none. For Result it compares the ok value to the
expected one if it is an ok or fails if it holds an error.
The value type of the Option or Result must implement PartialEq<E>
where E is the type of the expected value.
To assert the error value of a Result use AssertHasError::has_error.
§Examples
use asserting::prelude::*;
let subject = Some(-3.14);
assert_that!(subject).has_value(-3.14);
let subject: Result<f64, String> = Ok(6.28);
assert_that!(subject).has_value(6.28);Required Methods§
Sourcefn has_value(self, expected: E) -> Self
fn has_value(self, expected: E) -> Self
Verifies that the subject holds a value that is equal to the expected one.
For Option it compares the value in Some(value) and for Result
it compares the value in Ok(value). If an Option is None or a
Result is Err(error) then the assertion fails.
§Examples
use asserting::prelude::*;
let subject = Some(-3.14);
assert_that!(subject).has_value(-3.14);
let subject: Result<f64, String> = Ok(6.28);
assert_that!(subject).has_value(6.28);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.