cachedhash/lib.rs
1#![forbid(unsafe_code)]
2#![warn(clippy::pedantic)]
3#![warn(clippy::cargo)]
4#![warn(clippy::nursery)]
5
6//! For a type `T`, [`CachedHash<T>`](CachedHash) wraps `T` and
7//! implements [`Hash`](https://doc.rust-lang.org/std/hash/trait.Hash.html) in a way that
8//! caches `T`'s hash value. This is useful when `T` is expensive to hash (for
9//! example if it contains a large vector) and you need to hash it multiple times
10//! with few modifications (for example by moving it between multiple
11//! [`HashSet`](https://doc.rust-lang.org/std/collections/struct.HashSet.html)s).
12//!
13//! Stored hash is invalidated whenever the stored value is accessed mutably (via
14//! [`DerefMut`](https://doc.rust-lang.org/std/ops/trait.DerefMut.html),
15//! [`AsMut`](https://doc.rust-lang.org/std/convert/trait.AsMut.html),
16//! [`BorrowMut`](https://doc.rust-lang.org/std/borrow/trait.BorrowMut.html)
17//! or explicitly via a provided [associated function](CachedHash::get_mut)).
18//! In order for the hash to be invalidated correctly the stored type cannot use
19//! interior mutability in a way that affects the hash. If this is the case, you
20//! can use [`CachedHash::invalidate_hash`](CachedHash::invalidate_hash)
21//! to invalidate the hash manually.
22
23mod atomic;
24mod cachedhash;
25
26pub use crate::cachedhash::CachedHash;