pub struct Interner { /* private fields */ }Expand description
String interner. See the module-level docs.
§Examples
use arena_lib::Interner;
let mut interner = Interner::new();
let a = interner.intern("user:42");
let b = interner.intern("user:42");
let c = interner.intern("user:7");
assert_eq!(a, b);
assert_ne!(a, c);
assert_eq!(interner.resolve(a), Some("user:42"));
assert_eq!(interner.len(), 2);Implementations§
Source§impl Interner
impl Interner
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates an empty interner with storage pre-reserved for capacity
distinct strings.
Sourcepub fn intern(&mut self, s: &str) -> Symbol
pub fn intern(&mut self, s: &str) -> Symbol
Interns s and returns its Symbol.
Idempotent: repeated calls with the same input return the same
symbol. Panics if the symbol counter would overflow u32::MAX
— use Interner::try_intern for the explicit fallible variant.
Sourcepub fn try_intern(&mut self, s: &str) -> Result<Symbol>
pub fn try_intern(&mut self, s: &str) -> Result<Symbol>
Interns s, returning a Symbol on success or
Error::CounterOverflow if the interner cannot represent more
distinct strings.
Sourcepub fn resolve(&self, symbol: Symbol) -> Option<&str>
pub fn resolve(&self, symbol: Symbol) -> Option<&str>
Returns the original string for symbol, or None if the symbol
did not come from this interner.
Sourcepub fn contains(&self, s: &str) -> bool
pub fn contains(&self, s: &str) -> bool
Returns true if s has already been interned.
Equivalent to Interner::lookup returning Some.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Interner
impl RefUnwindSafe for Interner
impl Send for Interner
impl Sync for Interner
impl Unpin for Interner
impl UnsafeUnpin for Interner
impl UnwindSafe for Interner
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