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
Rc
s (or twoArc
s) 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§
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
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§impl<'a, T: ?Sized> Id for Weak<T>
std::rc::Weak
s are identical if they share the same reference counter
impl<'a, T: ?Sized> Id for Weak<T>
std::rc::Weak
s are identical if they share the same reference counter
Source§impl<'a, T: ?Sized> Id for Weak<T>
std::sync::Weak
s are identical if they share the same reference counter
impl<'a, T: ?Sized> Id for Weak<T>
std::sync::Weak
s are identical if they share the same reference counter