pub struct SymbolStore { /* private fields */ }Expand description
An append-only, deduplicating registry of identifier strings.
Interning takes &self, not &mut self: elaboration and typechecking both
mint new derived names mid-pass (qualify_key’s "M.x", $-mangled
module keys, "%patbind…", fresh desugar names like "%cmd_arg0",
qualified constructor lookup keys), so the store must stay interned-into
while the tree it brands is being walked. Hence the interior mutability.
Entries are never removed or mutated, which is what makes resolve
able to hand out &strs that live as long as the store borrow.
Implementations§
Source§impl SymbolStore
impl SymbolStore
pub fn new() -> SymbolStore
Sourcepub fn intern<'s>(&'s self, text: &str) -> Symbol<'s>
pub fn intern<'s>(&'s self, text: &str) -> Symbol<'s>
Intern text, returning its symbol. Interning the same text twice
returns the same symbol.
Sourcepub fn resolve<'s>(&'s self, sym: Symbol<'s>) -> &'s str
pub fn resolve<'s>(&'s self, sym: Symbol<'s>) -> &'s str
The text sym was interned from.
§Panics
If sym was minted by a different store that happened to share this
one’s borrow lifetime and holds more entries than this one. The brand
makes that hard to write by accident and it is not unsound — the bounds
check below turns it into a panic rather than a bogus read — but a
program should still keep one store per pipeline run.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
How many distinct strings have been interned. (Also the index the next new symbol will get — useful for sizing dense side-tables.)
pub fn is_empty(&self) -> bool
Trait Implementations§
Source§impl Debug for SymbolStore
impl Debug for SymbolStore
Source§impl Default for SymbolStore
impl Default for SymbolStore
Source§fn default() -> SymbolStore
fn default() -> SymbolStore
Auto Trait Implementations§
impl !Freeze for SymbolStore
impl !RefUnwindSafe for SymbolStore
impl !Sync for SymbolStore
impl Send for SymbolStore
impl Unpin for SymbolStore
impl UnsafeUnpin for SymbolStore
impl UnwindSafe for SymbolStore
Blanket Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more