Skip to main content

Module dyn_eq

Module dyn_eq 

Source
Expand description

Equality between trait objects.

A trait with DynEq as a supertrait can have PartialEq and Eq implemented for its objects by eq_trait_object!. Objects of two different concrete types are never equal; two of the same type compare with that type’s own Eq.

Import DynEq in the modules that call dyn_eq and nowhere else — do not re-export it from a prelude. The blanket impl also covers Box<dyn Trait>, whose dyn_eq downcasts to the box and so answers false for every comparison. Method resolution reaches that impl only where the trait is in scope, so a wide re-export silently turns boxed.dyn_eq(other) from a comparison of the pointees into a constant false.

Macros§

eq_trait_object
Implement PartialEq and Eq for the objects of a trait having DynEq as a supertrait, in all four Send/Sync combinations.

Traits§

DynEq
Type-erased equality, blanket-implemented for every Eq + 'static type.