Trait EntityEquivalent

Source
pub unsafe trait EntityEquivalent: ContainsEntity + Eq { }
Expand description

A trait for types that represent an Entity.

Comparison trait behavior between an EntityEquivalent type and its underlying entity will match. This property includes PartialEq, Eq, PartialOrd, Ord and Hash, and remains even after Clone and/or Borrow calls.

§Safety

Any PartialEq, Eq, PartialOrd, and Ord impls must evaluate the same for Self and its underlying entity. x.entity() == y.entity() must be equivalent to x == y.

The above equivalence must also hold through and between calls to any Clone and Borrow/BorrowMut impls in place of entity().

The result of entity() must be unaffected by any interior mutability.

The aforementioned properties imply determinism in both entity() calls and comparison trait behavior.

All Hash impls except that for Entity must delegate to the Hash impl of another EntityEquivalent type. All conversions to the delegatee within the Hash impl must follow entity() equivalence.

It should be noted that Hash is not a comparison trait, and with Hash::hash being forcibly generic over all Hashers, cannot guarantee determinism or uniqueness of any final hash values on its own. To obtain hash values forming the same total order as Entity, any Hasher used must be deterministic and concerning Entity, collisionless. Standard library hash collections handle collisions with an Eq fallback, but do not account for determinism when BuildHasher is unspecified,.

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§

Source§

impl<T> EntityEquivalent for &T

Source§

impl<T> EntityEquivalent for &mut T

Source§

impl<T> EntityEquivalent for Rc<T>

Implementors§