2 unstable releases

Uses new Rust 2024

0.2.0 Oct 23, 2025
0.1.0 Oct 23, 2025

#4 in #fxhash

0BSD license

11KB
201 lines

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

Dependencies

~0.5–1MB
~21K SLoC