Expand description
This module helps you efficiently store and retrieve values using interning.
Interning is a neat trick that keeps only one copy of identical values, saving memory
and making comparisons super fast. Here, we provide the Interned<T> struct and the Internable trait
to make interning easy for different data types.
The Interner struct handles caching for common types like String, PathBuf, and Vec<String>,
while the Cache struct acts as a write-once storage for linking computation steps with their results.
Β§Thread Safety
We use Mutex to make sure interning and retrieval are thread-safe. But keep in mindβonce a value is
interned, it sticks around for the entire lifetime of the program.
Re-exportsΒ§
use std::any::Any;πuse std::any::TypeId;πuse std::borrow::Borrow;πuse std::cell::RefCell;πuse std::cmp::Ordering;πuse std::collections::HashMap;πuse std::fmt::Debug;πuse std::fmt::Debug;πuse std::hash::Hash;πuse std::hash::Hash;πuse std::hash::Hasher;πuse std::marker::PhantomData;πuse std::ops::Deref;πuse std::sync::LazyLock;πuse std::sync::Mutex;πuse std::fmt;πuse std::mem;πuse crate::core::builder::Step;π
StructsΒ§
- Cache
- This is essentially a
HashMapwhich allows storing any type in its input and any type in its output. It is a write-once cache; values are never evicted, which means that references to the value can safely be returned from theget()method. - Interned
- Represents an interned value of type
T, allowing for efficient comparisons and retrieval. - Interner
- A global interner for managing interned values of common types.
- TyIntern π
- A structure for managing the interning of values of type
T.
StaticsΒ§
- INTERNER
- A global instance of
Internerthat caches common interned values.
TraitsΒ§
- Internable π
- Defines the behavior required for a type to be internable.