pub struct NameIndex { /* private fields */ }Expand description
Bidirectional mapping between declaration names and compact u32 identifiers.
Assigning a dense integer id to each name enables O(1) lookup by id and compact storage in downstream indices.
Implementations§
Source§impl NameIndex
impl NameIndex
Sourcepub fn insert(&mut self, name: &str) -> u32
pub fn insert(&mut self, name: &str) -> u32
Insert name and return its assigned id.
If name was already inserted the existing id is returned unchanged;
no duplicate entry is created.
Sourcepub fn lookup_id(&self, name: &str) -> Option<u32>
pub fn lookup_id(&self, name: &str) -> Option<u32>
Look up the id of name, returning None if it has not been inserted.
Sourcepub fn lookup_name(&self, id: u32) -> Option<&str>
pub fn lookup_name(&self, id: u32) -> Option<&str>
Look up the name string for id, returning None if out of range.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NameIndex
impl RefUnwindSafe for NameIndex
impl Send for NameIndex
impl Sync for NameIndex
impl Unpin for NameIndex
impl UnsafeUnpin for NameIndex
impl UnwindSafe for NameIndex
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
Mutably borrows from an owned value. Read more