| Crates.io | detain |
| lib.rs | detain |
| version | 0.2.0 |
| created_at | 2025-10-23 20:56:00.352162+00 |
| updated_at | 2025-10-23 21:46:51.826134+00 |
| description | String interner |
| homepage | |
| repository | https://git.sr.ht/~akhil/detain/tree |
| max_upload_size | |
| id | 1897689 |
| size | 22,867 |
Fast, simple string interner.
use detain::Interner;
let mut interner = Interner::new();
let hello = interner.intern("hello");
let world = interner.intern("world");
let hello2 = interner.intern("hello");
assert_eq!(hello, hello2);
assert_eq!(interner.resolve(hello), "hello");
Symbol is 4 bytesEdit COMMON in src/lib.rs to add your frequently-used strings:
static COMMON: phf::Map<&'static str, u32> = phf_map! {
"x" => 0, "y" => 1, "your_identifier" => 2, // sequential indices
};
# Unit tests
cargo test
# Property-based tests (100 cases per test by default)
cargo test proptests
# Fuzz testing
cargo +nightly fuzz run fuzz_interner -- -runs=10000
cargo +nightly fuzz run fuzz_common -- -runs=10000
# Miri (detects undefined behavior, proptests auto-skipped)
cargo +nightly miri test
0BSD