pub trait FmtOrd:
Display
+ Ord
+ FmtEq { }Expand description
A marker trait for types whose ordering is the same as ordering between its Display
representation.
When T implements FmtOrd, the following property must be upheld for all a: T and b: T:
assert_eq!(a.cmp(&b), (*format!("{}", a)).cmp(&format!("{}", b)));In other words (assuming that no ill-defined specialization is involved):
a ⋛ b <-> a.to_string() ⋛ b.to_string()§Colloraries
From str: Ord and the above property, it follows that T satisfies Ord
trait’s contract.
§Examples
Integer primitives do not satisfy the property.
assert!(42 < 240);
// but...
assert!(42.to_string() > 240.to_string());Wrapping any Display type with fmt_cmp::Cmp makes it FmtOrd:
assert!(fmt_cmp::Cmp(42) > fmt_cmp::Cmp(240));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.