Trait dyn_ord::DynEq

source ·
pub trait DynEq: Any { }
Expand description

A trait for comparing dynamically-typed values for equality.

After coercing your values to a trait object of type DynEq, you can directly compare references (and smart pointers) to instances via the usual == or != operators.

Trait objects created from different concrete underlying types are considered not equal. Trait objects created from the same underlying concrete type are compared using PartialEq.

let x: &dyn DynEq = &42;
let y: &dyn DynEq = &String::from("qux");
let z: &dyn DynEq = &String::from("baz");

assert!(*x == *x);
assert!(*x != *y);
assert!(*x != *z);

assert!(*y != *x);
assert!(*y == *y);
assert!(*y != *z);

assert!(*z != *x);
assert!(*z != *y);
assert!(*z == *z);

Trait Implementations§


impl PartialEq<dyn DynEq + '_> for dyn DynEq + '_


fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.



impl<T: Any + PartialEq> DynEq for T