pub trait FmtEq: Display + Eq { }Expand description
A marker trait for types whose equivalence relation is the same as equivalence between its
Display representation.
When T implements FmtEq, the following property must be upheld for all a: T and b: T:
assert_eq!(a == b, *format!("{}", a) == *format!("{}", b));In other words (assuming that no ill-defined specialization is involved):
a == b <-> a.to_string() == b.to_string()§Corollaries
From str: Eq and the above property, it follows that T satisfies Eq
trait’s contract, i.e., reflexivity, symmetricity and transitivity of == operator.
§Examples
Floating-point number primitives do not satisfy the property (they are not even Eq):
assert_eq!(0.0, -0.0);
assert_ne!(0.0.to_string(), (-0.0).to_string());
assert_ne!(f64::NAN, f64::NAN);
assert_eq!(f64::NAN.to_string(), f64::NAN.to_string());Wrapping any Display type with fmt_cmp::Cmp makes it FmtEq:
assert_ne!(fmt_cmp::Cmp(0.0), fmt_cmp::Cmp(-0.0));
assert_eq!(fmt_cmp::Cmp(f64::NAN), fmt_cmp::Cmp(f64::NAN));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.