Crate string_interner[][src]

Expand description

Caches strings efficiently, with minimal memory footprint and associates them with unique symbols. These symbols allow constant time comparisons and look-ups to the underlying interned strings.

Example: Interning & Symbols

use string_interner::StringInterner;

let mut interner = StringInterner::default();
let sym0 = interner.get_or_intern("Elephant");
let sym1 = interner.get_or_intern("Tiger");
let sym2 = interner.get_or_intern("Horse");
let sym3 = interner.get_or_intern("Tiger");
assert_ne!(sym0, sym1);
assert_ne!(sym0, sym2);
assert_ne!(sym1, sym2);
assert_eq!(sym1, sym3); // same!

Example: Creation by FromIterator

let interner = vec!["Elephant", "Tiger", "Horse", "Tiger"]
    .into_iter()
    .collect::<StringInterner>();

Example: Look-up

let mut interner = StringInterner::default();
let sym = interner.get_or_intern("Banana");
assert_eq!(interner.resolve(sym), Some("Banana"));

Example: Iteration

let interner = vec!["Earth", "Water", "Fire", "Air"]
    .into_iter()
    .collect::<StringInterner>();
for (sym, str) in &interner {
    // iteration code here!
}

Modules

Backends for the StringInterner.

Interfaces and types to be used as symbols for the StringInterner.

Structs

Data structure to intern and resolve strings.

Traits

Types implementing this trait can be used as symbols for string interners.

Type Definitions

The default backend recommended for general use.

Default hasher for HashMap.

The symbol type that is used by default.