eq

Function eq 

Source
pub fn eq<T: Display + ?Sized, U: Display + ?Sized>(lhs: &T, rhs: &U) -> bool
Expand description

Tests two values for equality in their Display representations.

This yields the same result as lhs.to_string() == rhs.to_string() without heap allocation.

§Note

This may call Display::fmt multiple times and if it emits different strings between the calls, the resulting value is unspecified.

Also, the Display implementations may not return error as described by the documentation of std::fmt. Doing so would result in an unspecified return value or might even cause a panic in a future version.

§Examples

Comparing floating-point numbers:

assert!(fmt_cmp::eq(&f64::NAN, &f64::NAN)); // `"NaN" == "NaN"`
assert!(!fmt_cmp::eq(&0.0, &-0.0)); // `"0" != "-0"`

Comparing values of different types:

assert!(fmt_cmp::eq(&format_args!("{:X}", 0x2A), "2A"));