Crate simple_interner

source ·
Expand description

A very simplistic interner based around giving out references rather than some placeholder symbol. This means that you can mostly transparently add interning into a system without requiring rewriting all of the code to work on a new Symbol type, asking the interener to concretize the symbols.

The typical use case for something like this is text processing chunks, where chunks are very likely to be repeated. For example, when parsing source code, identifiers are likely to come up multiple times. Rather than have a String allocated for every occurrence of the identifier separately, interners allow you to store Symbol. This additionally allows comparing symbols to be much quicker than comparing the full interned string.

This crate exists to give the option of using the simplest interface. For a more featureful interner, consider using a different crate, such as

crategloballocal'static opt1str-onlysymbol sizesymbols deref
simple-internermanual2yesnono&Tyes
intaglionoyesyesyesu32no
internmentrc3yesnono&Tyes
lassonoyesyesyesu8usizeno
string-internernoyesoptionallyyesu16usizeno
string_cachestatic onlyrc3buildscriptyesu64yes
symbol_tableyesyesnoyesu32global only
ustryesnonoyesusizeyes

(PRs to this table are welcome!)


  1. The interner stores &'static references without copying the pointee into the store, e.g. storing Cow<'static, str> instead of Box<str>

  2. At the moment, creating the Interner inside a static, using Interner::with_hasher, requires the hashbrown feature to be enabled. 

  3. Uses reference counting to collect globally unused symbols. 

Structs

An item interned by an Interner.
An interner based on a HashSet. See the crate-level docs for more.