pub trait GetHash {
// Required methods
fn hash(&self) -> Hash;
fn cached_hash(&self) -> Option<Hash>;
// Provided method
fn clear_cached_hash(&self) { ... }
}
internal
only.Expand description
A type which can be transformed into a Hash
, either by retrieving a cached hash, computing a
hash for it, or some combination of both.
Required Methods§
Sourcefn hash(&self) -> Hash
fn hash(&self) -> Hash
Get the hash of this item.
§Correctness
This function must return the same hash for the same item. It is permissible to use internal mutability to cache hashes, but caching must ensure that the item cannot be mutated without recalculating the hash.
Sourcefn cached_hash(&self) -> Option<Hash>
fn cached_hash(&self) -> Option<Hash>
Get the hash of this item, only if the hash is already cached and does not require recalculation.
§Correctness
It will not cause correctness issues to return a hash after recalculating it, but users of this function expect it to be reliably fast, so it may cause unexpected performance issues if this function performs any significant work.
Provided Methods§
Sourcefn clear_cached_hash(&self)
fn clear_cached_hash(&self)
If there is a hash cached, clear the cache.
By default, this does nothing. Override this if there is a cache.