pub struct ManuallyHash<T: ?Sized> { /* private fields */ }
Expand description
A wrapper type with a manually computed hash.
This can be used to turn an unhashable type into a hashable one where the hash is provided manually. Typically, the hash is derived from the data which was used to construct to the unhashable type.
For instance, you could hash the bytes that were parsed into an unhashable data structure.
§Equality
Because Typst uses high-quality 128 bit hashes in all places, the risk of a
hash collision is reduced to an absolute minimum. Therefore, this type
additionally provides PartialEq
and Eq
implementations that compare by
hash instead of by value. For this to be correct, your hash implementation
must feed all information relevant to the PartialEq
impl to the
hasher.
Implementations§
Source§impl<T> ManuallyHash<T>
impl<T> ManuallyHash<T>
Sourcepub fn new(value: T, hash: u128) -> Self
pub fn new(value: T, hash: u128) -> Self
Wraps an item with a pre-computed hash.
The hash should be computed with typst_utils::hash128
.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Returns the wrapped value.
Trait Implementations§
Source§impl<T: Clone + ?Sized> Clone for ManuallyHash<T>
impl<T: Clone + ?Sized> Clone for ManuallyHash<T>
Source§fn clone(&self) -> ManuallyHash<T>
fn clone(&self) -> ManuallyHash<T>
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<T: Debug> Debug for ManuallyHash<T>
impl<T: Debug> Debug for ManuallyHash<T>
Source§impl<T: ?Sized> Deref for ManuallyHash<T>
impl<T: ?Sized> Deref for ManuallyHash<T>
Source§impl<T: ?Sized> Hash for ManuallyHash<T>
impl<T: ?Sized> Hash for ManuallyHash<T>
Source§impl<T: ?Sized> PartialEq for ManuallyHash<T>
impl<T: ?Sized> PartialEq for ManuallyHash<T>
impl<T: ?Sized> Eq for ManuallyHash<T>
Auto Trait Implementations§
impl<T> Freeze for ManuallyHash<T>
impl<T> RefUnwindSafe for ManuallyHash<T>where
T: RefUnwindSafe + ?Sized,
impl<T> Send for ManuallyHash<T>
impl<T> Sync for ManuallyHash<T>
impl<T> Unpin for ManuallyHash<T>
impl<T> UnwindSafe for ManuallyHash<T>where
T: UnwindSafe + ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more