7 releases
Uses new Rust 2024
new 0.3.1 | Mar 27, 2025 |
---|---|
0.3.0 | Mar 27, 2025 |
0.2.1 | Mar 27, 2025 |
0.1.2 | Mar 26, 2025 |
0.1.1 | Jan 12, 2025 |
#663 in Data structures
86 downloads per month
13KB
255 lines
Object interner in Rust
== Documentation ==
To build the documentation, run cargo doc
Or browse it online at https://docs.rs/interns
== Dependencies == This crate works on nightly rust with zero dependencies. But since it makes use of the raw_entry_mut experimental API, we need to use hashbrown on stable rust. By default the hashbrown feature is enabled.
lib.rs
:
An object interner library
The main element of this crate is the Interner
struct.
It allows to build a "storage" of any kind of object that avoids repetition and memory waste.
Example (String interner)
use interns::*;
let mut interner = Interner::<str>::default();
let a = interner.get_or_intern("hello");
let b = interner.get_or_intern("world");
let c = interner.get_or_intern("hello");
let a_resolv = interner.resolve(a);
let b_resolv = interner.resolve(b);
let c_resolv = interner.resolve(c);
assert_eq!(a_resolv, Some("hello"));
assert_eq!(b_resolv, Some("world"));
assert_eq!(c_resolv, Some("hello"));
assert_eq!(a, c);
assert_ne!(a, b);
assert_ne!(b, c);
Dependencies
~590KB