[−][src]Crate intaglio
This crate provides a library for interning strings.
The primary API is a symbol table. Its API is similar to a bimap in that symbols can resolve an underlying string and a string slice can retrieve its associated symbol.
For more specific details on the API for interning strings into a symbol
table, please see the documentation for the SymbolTable
type.
Example
let mut table = SymbolTable::new(); let sym_id = table.intern("abc")?; assert_eq!(sym_id, table.intern("abc".to_string())?); assert!(table.contains(sym_id)); assert!(table.is_interned("abc"));
String interning
Intaglio SymbolTable
s store at most one copy of a string. All requests to
intern a string that is already present in the table, regardless of whether
the string is an owned String
or borrowed &'static str
, will return the
same immutable Symbol
.
Symbol
s are u32
indexes into a SymbolTable
that are cheap to
compare, copy, store, and send.
Allocations
SymbolTable
exposes several constructors for tuning the initial allocated
size of the table. It also exposes several APIs for tuning the table's
memory usage such as SymbolTable::reserve
and
SymbolTable::shrink_to_fit
.
SymbolTable::intern
does not clone or copy interned strings. It takes
ownership of the string contents with no additional allocations. Owned
strings are leaked with Box::leak
and recovered and deallocated when the
table is dropped.
Crate features
All features are enabled by default.
- bytes - Enables an additional symbol table implementation for
interning bytestrings (
Vec<u8>
and&'static [u8]
). Disabling this drops thebstr
dependency.
Modules
bytes | Intern arbitrary bytes. |
Structs
AllSymbols | An iterator over all |
Iter | An iterator over all symbols and interned strings in a |
Strings | An iterator over all interned strings in a |
Symbol | Identifier bound to an interned string. |
SymbolOverflowError | Error returned when a |
SymbolTable | UTF-8 string interner. |
Constants
DEFAULT_SYMBOL_TABLE_CAPACITY | Default capacity for new a |