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.
Implementations on Foreign Types§
impl FmtEq for Infallible
impl FmtEq for bool
impl FmtEq for i8
impl FmtEq for i16
impl FmtEq for i32
impl FmtEq for i64
impl FmtEq for i128
impl FmtEq for isize
impl FmtEq for str
impl FmtEq for u8
impl FmtEq for u16
impl FmtEq for u32
impl FmtEq for u64
impl FmtEq for u128
impl FmtEq for usize
impl FmtEq for String
Available on crate feature
alloc only.impl<P: Borrow<<P as Deref>::Target> + Deref + Display> FmtEq for Pin<P>
impl<T: FmtEq + ToOwned + ?Sized> FmtEq for Cow<'_, T>
Available on crate feature
alloc only.impl<T: FmtEq + ?Sized> FmtEq for &T
impl<T: FmtEq + ?Sized> FmtEq for &mut T
impl<T: FmtEq + ?Sized> FmtEq for Box<T>
Available on crate feature
alloc only.impl<T: FmtEq + ?Sized> FmtEq for Rc<T>
Available on crate feature
alloc only.impl<T: FmtEq + ?Sized> FmtEq for Arc<T>
Available on crate feature
alloc only.