Struct prehash::Prehashed

source ·
pub struct Prehashed<T: ?Sized, H = u64> { /* private fields */ }
Expand description

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§

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.

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.

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.

Creates a new Prehashed object from the specified value and precomputed hash.

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.

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.

Available on crate feature 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.

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.

Constructs a Prehashed object by hashing a value with a hasher created the specified builder.

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§

Converts this type into a shared reference of the (usually inferred) input type.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Dereferences the value.
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.