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.
Implementations on Foreign Types§
impl FmtOrd for Infallible
impl FmtOrd for bool
impl FmtOrd for str
impl FmtOrd for String
Available on crate feature
alloc only.impl<P: Borrow<<P as Deref>::Target> + Deref + Display> FmtOrd for Pin<P>
impl<T: FmtOrd + ToOwned + ?Sized> FmtOrd for Cow<'_, T>
Available on crate feature
alloc only.impl<T: FmtOrd + ?Sized> FmtOrd for &T
impl<T: FmtOrd + ?Sized> FmtOrd for &mut T
impl<T: FmtOrd + ?Sized> FmtOrd for Box<T>
Available on crate feature
alloc only.impl<T: FmtOrd + ?Sized> FmtOrd for Rc<T>
Available on crate feature
alloc only.impl<T: FmtOrd + ?Sized> FmtOrd for Arc<T>
Available on crate feature
alloc only.