[−][src]Struct prehash::Prehashed
A value (of type T
) stored along with a precomputed hash (of type H
,
which defaults to u64
).
When a hash of this value is requested, the stored precomputed hash is hashed instead of the value itself. However, when an equality test is requested, the contained value is used.
Prehashed
values are unaware of the hash algorithm used to compute the
hash. Algorithms may misbehave if used with Prehashed
values created by
different hashers.
Example
See the crate-level documentation.
Implementations
impl<T: ?Sized, H> Prehashed<T, H>
[src]
#[must_use]pub fn as_parts(pre: &Self) -> (&T, &H)
[src]
Returns references to the value and its precomputed hash.
Invocation
This is an associated function, so it is invoked like
Prehashed::as_parts(prehashed)
. This is so this method does not
interfere with automatic dereferencing as the contained value.
Notes
If the value or hash are interiorly mutable, it is possible to cause a mismatch between the precomputed hash and the value. This may cause certain algorithms to malfunction.
#[must_use]pub fn as_inner(pre: &Self) -> &T
[src]
Returns a reference to the contained value.
Invocation
This is an associated function, so it is invoked like
Prehashed::as_inner(prehashed)
. This is so this method does not
interfere with automatic dereferencing as the contained value.
Notes
If the value is interiorly mutable, it is possible to cause a mismatch between the precomputed hash and the value. This may cause certain algorithms to malfunction.
#[must_use]pub fn as_hash(pre: &Self) -> &H
[src]
Returns a reference to the contained hash.
Invocation
This is an associated function, so it is invoked like
Prehashed::as_hash(prehashed)
. This is so this method does not
interfere with automatic dereferencing as the contained value.
Notes
If the hash is interiorly mutable, it is possible to cause a mismatch between the precomputed hash and the value. This may cause certain algorithms to malfunction.
impl<T, H> Prehashed<T, H>
[src]
#[must_use]pub const fn new(value: T, hash: H) -> Self
[src]
Creates a new Prehashed
object from the specified value and
precomputed hash.
#[must_use]pub fn into_parts(pre: Self) -> (T, H)
[src]
Deconstructs the Prehashed
object into the value and its precomputed
hash.
These parts can be passed to new
to reconstruct the original
Prehashed
object.
Invocation
This is an associated function, so it is invoked like
Prehashed::into_parts(prehashed)
. This is so this method does not
interfere with automatic dereferencing as the contained value.
#[must_use]pub fn into_inner(pre: Self) -> T
[src]
Deconstructs the Prehashed
object and returns the contained value.
The precomputed hash is discarded.
Invocation
This is an associated function, so it is invoked like
Prehashed::into_inner(prehashed)
. This is so this method does not
interfere with automatic dereferencing as the contained value.
impl<T: Hash> Prehashed<T, u64>
[src]
#[must_use]pub fn with_default(value: T) -> Self
[src]
std
only.Constructs a Prehashed
object by hashing a value with the
default hasher.
Security
Consider using with_builder
if collision-based denial of service
attacks are a potential concern.
#[must_use]pub fn with_hasher<H: Default + Hasher>(value: T) -> Self
[src]
Constructs a Prehashed
object by hashing a value with a default
instance of the specified Hasher
type, H
.
Invocation
You will need to use "turbofish operator" to invoke this method:
Prehashed::with_hasher::<Hasher>(value)
Security
Consider using with_builder
if collision-based denial of service
attacks are a potential concern.
#[must_use]pub fn with_builder<B: BuildHasher + ?Sized>(value: T, build: &B) -> Self
[src]
Constructs a Prehashed
object by hashing a value with a hasher created
the specified builder.
impl<T: PartialEq + ?Sized, H: Eq> Prehashed<T, H>
[src]
#[must_use]pub fn fast_eq(lhs: &Self, rhs: &Self) -> bool
[src]
Compares two Prehashed
values for equality, using the precomputed hash
to quickly test for inequality.
Invocation
This is an associated function, so it is invoked like
Prehashed::fast_eq(a, b)
. This is so this method does not interfere
with automatic dereferencing as the contained value.
Notes
The PartialEq
implementation for Prehashed
does not check the hash
value for early inequality because this would slow down algorithms which
execute a deep equality test only once a hash equality test has
indicated possible equivalence. In that sense, fast_eq
strictly
slower if the hashes have already been tested for equality.
Trait Implementations
impl<T: ?Sized, H> AsRef<T> for Prehashed<T, H>
[src]
impl<T: Copy + ?Sized, H: Clone> Clone for Prehashed<T, H>
[src]
pub fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Copy + ?Sized, H: Copy> Copy for Prehashed<T, H>
[src]
impl<T: Debug + ?Sized, H: Debug> Debug for Prehashed<T, H>
[src]
impl<T: ?Sized, H> Deref for Prehashed<T, H>
[src]
impl<T: Display + ?Sized, H> Display for Prehashed<T, H>
[src]
impl<T: Eq + ?Sized, H> Eq for Prehashed<T, H>
[src]
impl<T: ?Sized, H: Hash> Hash for Prehashed<T, H>
[src]
pub fn hash<S: Hasher>(&self, state: &mut S)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T: PartialEq + ?Sized, H> PartialEq<Prehashed<T, H>> for Prehashed<T, H>
[src]
pub fn eq(&self, other: &Self) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T: PartialEq + ?Sized, H> PartialEq<T> for Prehashed<T, H>
[src]
Auto Trait Implementations
impl<T: ?Sized, H> RefUnwindSafe for Prehashed<T, H> where
H: RefUnwindSafe,
T: RefUnwindSafe,
H: RefUnwindSafe,
T: RefUnwindSafe,
impl<T: ?Sized, H> Send for Prehashed<T, H> where
H: Send,
T: Send,
H: Send,
T: Send,
impl<T: ?Sized, H> Sync for Prehashed<T, H> where
H: Sync,
T: Sync,
H: Sync,
T: Sync,
impl<T: ?Sized, H> Unpin for Prehashed<T, H> where
H: Unpin,
T: Unpin,
H: Unpin,
T: Unpin,
impl<T: ?Sized, H> UnwindSafe for Prehashed<T, H> where
H: UnwindSafe,
T: UnwindSafe,
H: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,