Trait Id

Source
pub trait Id {
    // Required methods
    fn same(&self, other: &Self) -> bool;
    fn hash<H: Hasher>(&self, state: &mut H);
}
Expand description

Type that can be compared in regard to identity (e.g. through address comparison) instead of equality (as done by PartialEq)

§Caveats / Notes

  • Two references (passed to same as references to the respective reference) are considered the same if they point to the same memory range. However, empty memory ranges (e.g. in case of empty slices or zero-sized types) are always considered identical, even if their base address is different.
  • Two Rcs (or two Arcs) are considered the same if they share the same reference counter (i.e. if they are clones). This also holds if their inner type is a zero-sized type.
  • Working with trait objects may cause surprising behavior due to current implementation of Id for references and Rust’s pointer comparison rules.

Required Methods§

Source

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

Check if two values are the same

Source

fn hash<H: Hasher>(&self, state: &mut H)

Perform hashing such that two identical values create equal hashes

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<'a, T: ?Sized> Id for &'a T

References are identical if their pointer representation is equal or if they both refer to a zero-sized value

Source§

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

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Source§

impl<'a, T: ?Sized> Id for Rc<T>

Rcs are identical if they share the same reference counter

Source§

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

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Source§

impl<'a, T: ?Sized> Id for Weak<T>

std::rc::Weaks are identical if they share the same reference counter

Source§

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

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Source§

impl<'a, T: ?Sized> Id for Arc<T>

Arcs are identical if they share the same reference counter

Source§

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

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Source§

impl<'a, T: ?Sized> Id for Weak<T>

std::sync::Weaks are identical if they share the same reference counter

Source§

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

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Implementors§