Struct symbol_table::SymbolTable
source · [−]pub struct SymbolTable<const N: usize = DEFAULT_N_SHARDS, S = DeterministicHashBuilder> { /* private fields */ }
Expand description
A table in which you can intern strings and get back Symbol
s.
The table is sharded N
times (default DEFAULT_N_SHARDS
)
for lower contention when accessing concurrently.
Implementations
sourceimpl SymbolTable<DEFAULT_N_SHARDS, DeterministicHashBuilder>
impl SymbolTable<DEFAULT_N_SHARDS, DeterministicHashBuilder>
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new SymbolTable
with the default generic arguments.
This symbol table will be determinisitic, using a seeded ahash.
sourceimpl<const N: usize, S: BuildHasher> SymbolTable<N, S>
impl<const N: usize, S: BuildHasher> SymbolTable<N, S>
sourcepub fn intern(&self, string: &str) -> Symbol
pub fn intern(&self, string: &str) -> Symbol
Intern a string into the SymbolTable
.
Note how this method only takes &self
, so it can be used concurrently.
Interning the same string will give the same symbol.
let mut table = symbol_table::SymbolTable::new();
assert_eq!(table.intern("foo"), table.intern("foo"));
sourcepub fn resolve(&self, sym: Symbol) -> &str
pub fn resolve(&self, sym: Symbol) -> &str
Resolve a symbol to the interned string.
The resolved string is immutable and will live as long as the
SymbolTable
.
let mut table = symbol_table::SymbolTable::new();
let foo = table.intern("foo");
assert_eq!(table.resolve(foo), "foo");
Trait Implementations
sourceimpl<const N: usize, S: Default + BuildHasher> Default for SymbolTable<N, S>
impl<const N: usize, S: Default + BuildHasher> Default for SymbolTable<N, S>
Auto Trait Implementations
impl<const N: usize, S> RefUnwindSafe for SymbolTable<N, S> where
S: RefUnwindSafe,
impl<const N: usize, S> Send for SymbolTable<N, S> where
S: Send,
impl<const N: usize, S> Sync for SymbolTable<N, S> where
S: Sync,
impl<const N: usize, S> Unpin for SymbolTable<N, S> where
S: Unpin,
impl<const N: usize, S> UnwindSafe for SymbolTable<N, S> where
S: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more