detain

Crates.iodetain
lib.rsdetain
version0.2.0
created_at2025-10-23 20:56:00.352162+00
updated_at2025-10-23 21:46:51.826134+00
descriptionString interner
homepage
repositoryhttps://git.sr.ht/~akhil/detain/tree
max_upload_size
id1897689
size22,867
Akhil Velagapudi (akhilles)

documentation

README

detain

Fast, simple string interner.

Usage

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");

Features

  • Compact: Symbol is 4 bytes
  • Fast: FxHash + optimized for 110 common IPC-2581 identifiers
  • Simple: Single growing arena, immutable, ~120 LOC

Customizing

Edit 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
};

Testing

# 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

License

0BSD

Commit count: 0

cargo fmt