pub struct StrInterner<'a> { /* private fields */ }Expand description
The string interner. See the module level documentation for more.
Implementations§
Source§impl<'a> StrInterner<'a>
impl<'a> StrInterner<'a>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new StrInterner.
Sourcepub fn intern(&self, arena: &'a Arena, value: &str) -> InternedStr<'a>
pub fn intern(&self, arena: &'a Arena, value: &str) -> InternedStr<'a>
Interns a string or returns a reference an already interned string.
§Example
let arena = rsjsonnet_lang::arena::Arena::new();
let interner = rsjsonnet_lang::interner::StrInterner::new();
let hello = interner.intern(&arena, "hello");
assert_eq!(hello.value(), "hello");Sourcepub fn get_interned(&self, value: &str) -> Option<InternedStr<'a>>
pub fn get_interned(&self, value: &str) -> Option<InternedStr<'a>>
Returns a reference to an already interned string if it exists.
§Example
let arena = rsjsonnet_lang::arena::Arena::new();
let interner = rsjsonnet_lang::interner::StrInterner::new();
let hello1 = interner.intern(&arena, "hello");
assert_eq!(hello1.value(), "hello");
let hello2 = interner.get_interned("hello").unwrap();
assert_eq!(hello2.value(), "hello");
let world = interner.get_interned("world");
assert!(world.is_none()); // Not previously internedTrait Implementations§
Auto Trait Implementations§
impl<'a> !Freeze for StrInterner<'a>
impl<'a> !RefUnwindSafe for StrInterner<'a>
impl<'a> Send for StrInterner<'a>
impl<'a> !Sync for StrInterner<'a>
impl<'a> Unpin for StrInterner<'a>
impl<'a> UnwindSafe for StrInterner<'a>
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