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