pub fn eq<T>(expected: T) -> EqMatcher<T>Expand description
Matches a value equal (in the sense of ==) to expected.
The type of expected must implement the PartialEq trait so that the
expected and actual values can be compared.
verify_that!(123, eq(123))?; // Passes
verify_that!(123, eq(234))?; // Failsexpected to actual must be comparable with one another via the
PartialEq trait. In most cases, this means that they must be of the same
type. However, there are a few cases where different but closely related
types are comparable, for example String with &str.
verify_that!(String::from("Some value"), eq("Some value"))?; // PassesIn most cases however, one must convert one of the arguments explicitly. This can be surprising when comparing integer types or references.
verify_that!(123u32, eq(123u64))?; // Does not compile
verify_that!(123u32 as u64, eq(123u64))?; // Passeslet actual: &T = ...;
let expected: T = T{...};
verify_that(actual, eq(expected))?; // Does not compile
verify_that(actual, eq(&expected))?; // CompilesWhen matching with string types (&str and String), one can set more
options on how equality is checked through the
StrMatcherConfigurator
extension trait, which is implemented for this matcher.