pub struct Intern<'a> { /* private fields */ }
Implementations§
Source§impl Intern<'_>
impl Intern<'_>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new intern table with the given capacity.
Sourcepub fn intern<V: Into<String> + AsRef<str>>(&mut self, input: V) -> InternId
pub fn intern<V: Into<String> + AsRef<str>>(&mut self, input: V) -> InternId
Intern a string. Returns the interned id. If the string is already interned, returns the existing id. The string is stored in the intern table for the lifetime of the program. The id is a 32-bit integer, so there can be at most 2^32 unique strings interned. If the limit is reached, this function will panic. The id is guaranteed to be unique for the lifetime of the program.
§Examples
use intern_string::Intern;
let mut intern = Intern::new();
let id = intern.intern("hello");
assert_eq!(intern.lookup(id), "hello");
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Intern<'a>
impl<'a> RefUnwindSafe for Intern<'a>
impl<'a> Send for Intern<'a>
impl<'a> Sync for Intern<'a>
impl<'a> Unpin for Intern<'a>
impl<'a> UnwindSafe for Intern<'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