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) -> Interner
pub fn with_capacity(cap: usize) -> Interner
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.
Trait Implementations§
Auto Trait Implementations§
impl !Send for Interner
impl !Sync for Interner
impl Freeze for Interner
impl RefUnwindSafe for Interner
impl Unpin for Interner
impl UnsafeUnpin for Interner
impl UnwindSafe for Interner
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.