Crates.io | cachedhash |
lib.rs | cachedhash |
version | 0.2.0 |
source | src |
created_at | 2022-10-04 20:15:27.063645 |
updated_at | 2024-02-14 10:47:55.546678 |
description | Wrapper for values that caches their hash. |
homepage | |
repository | https://github.com/pali6/cachedhash |
max_upload_size | |
id | 680106 |
size | 36,835 |
For a type T
, CachedHash<T>
wraps T
and implements Hash
in a way that
caches T
's hash value. This is useful when T
is expensive to hash (for
example if it contains a large vector) and you need to hash it multiple times
with few modifications (for example by moving it between multiple HashSet
s).
Stored hash is invalidated whenever the stored value is accessed mutably (via
DerefMut
, AsMut
, BorrowMut
or explicitly via a provided associated function).
In order for the hash to be invalidated correctly the stored type cannot use
interior mutability in a way that affects the hash. If this is the case, you
can use CachedHash::invalidate_hash
to invalidate the hash manually.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.