pub struct Interner { /* private fields */ }Expand description
A string interner that maps strings to Symbol handles.
Thread-local, single-owner. For a Nix evaluator this is sufficient because evaluation is single-threaded.
Implementations§
Source§impl Interner
impl Interner
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Create an interner with pre-allocated capacity. Use when you know the approximate identifier count upfront — avoids hashmap resizes during the hot path.
Sourcepub fn intern(&mut self, s: &str) -> Symbol
pub fn intern(&mut self, s: &str) -> Symbol
Intern a string, returning its symbol. If the string was already interned, returns the existing symbol (O(1) amortized).
Sourcepub fn resolve(&self, sym: Symbol) -> &str
pub fn resolve(&self, sym: Symbol) -> &str
Resolve a symbol back to its string content.
§Panics
Panics if the symbol was not produced by this interner.
Sourcepub fn resolve_rc(&self, sym: Symbol) -> Rc<str>
pub fn resolve_rc(&self, sym: Symbol) -> Rc<str>
Resolve a symbol to its shared Rc<str> handle. Cheap to clone
and pass around; prefer this over resolve(...).to_string() in
hot paths.
§Panics
Panics if the symbol was not produced by this interner.
Sourcepub fn try_resolve(&self, sym: Symbol) -> Option<&str>
pub fn try_resolve(&self, sym: Symbol) -> Option<&str>
Try to resolve a symbol, returning None if invalid.