pub struct StringTable(/* private fields */);
Implementations§
Source§impl StringTable
impl StringTable
pub fn with_hasher(hash_builder: FxBuildHasher) -> Self
Methods from Deref<Target = Rodeo<Spur, FxBuildHasher>>§
Sourcepub fn get_or_intern<T>(&mut self, val: T) -> K
pub fn get_or_intern<T>(&mut self, val: T) -> K
Get the key for a string, interning it if it does not yet exist
§Panics
Panics if the key’s try_from_usize
function fails. With the default keys, this means that
you’ve interned more strings than it can handle. (For Spur
this means that u32::MAX - 1
unique strings were interned)
§Example
use lasso::Rodeo;
let mut rodeo = Rodeo::default();
// Interned the string
let key = rodeo.get_or_intern("Strings of things with wings and dings");
assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));
// No string was interned, as it was already contained
let key = rodeo.get_or_intern("Strings of things with wings and dings");
assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));
Sourcepub fn try_get_or_intern<T>(&mut self, val: T) -> Result<K, LassoError>
pub fn try_get_or_intern<T>(&mut self, val: T) -> Result<K, LassoError>
Get the key for a string, interning it if it does not yet exist
§Example
use lasso::Rodeo;
let mut rodeo = Rodeo::default();
// Interned the string
let key = rodeo.try_get_or_intern("Strings of things with wings and dings").unwrap();
assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));
// No string was interned, as it was already contained
let key = rodeo.try_get_or_intern("Strings of things with wings and dings").unwrap();
assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));
Sourcepub fn get_or_intern_static(&mut self, string: &'static str) -> K
pub fn get_or_intern_static(&mut self, string: &'static str) -> K
Get the key for a static string, interning it if it does not yet exist
This will not reallocate or copy the given string
§Panics
Panics if the key’s try_from_usize
function fails. With the default keys, this means that
you’ve interned more strings than it can handle. (For Spur
this means that u32::MAX - 1
unique strings were interned)
§Example
use lasso::Rodeo;
let mut rodeo = Rodeo::default();
// Interned the string
let key = rodeo.get_or_intern_static("Strings of things with wings and dings");
assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));
// No string was interned, as it was already contained
let key = rodeo.get_or_intern_static("Strings of things with wings and dings");
assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));
Sourcepub fn try_get_or_intern_static(
&mut self,
string: &'static str,
) -> Result<K, LassoError>
pub fn try_get_or_intern_static( &mut self, string: &'static str, ) -> Result<K, LassoError>
Get the key for a static string, interning it if it does not yet exist
This will not reallocate or copy the given string
§Example
use lasso::Rodeo;
let mut rodeo = Rodeo::default();
// Interned the string
let key = rodeo.try_get_or_intern_static("Strings of things with wings and dings").unwrap();
assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));
// No string was interned, as it was already contained
let key = rodeo.try_get_or_intern_static("Strings of things with wings and dings").unwrap();
assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));
Sourcepub fn get<T>(&self, val: T) -> Option<K>
pub fn get<T>(&self, val: T) -> Option<K>
Get the key value of a string, returning None
if it doesn’t exist
§Example
use lasso::Rodeo;
let mut rodeo = Rodeo::default();
let key = rodeo.get_or_intern("Strings of things with wings and dings");
assert_eq!(Some(key), rodeo.get("Strings of things with wings and dings"));
assert_eq!(None, rodeo.get("This string isn't interned"));
Sourcepub fn contains<T>(&self, val: T) -> bool
pub fn contains<T>(&self, val: T) -> bool
Returns true
if the given string has been interned
§Example
use lasso::Rodeo;
let mut rodeo = Rodeo::default();
let key = rodeo.get_or_intern("Strings of things with wings and dings");
assert!(rodeo.contains("Strings of things with wings and dings"));
assert!(!rodeo.contains("This string isn't interned"));
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Returns true
if the given key exists in the current interner
§Example
use lasso::Rodeo;
let mut rodeo = Rodeo::default();
let key = rodeo.get_or_intern("Strings of things with wings and dings");
assert!(rodeo.contains_key(&key));
assert!(!rodeo.contains_key(&key_that_doesnt_exist));
Sourcepub fn resolve<'a>(&'a self, key: &K) -> &'a str
pub fn resolve<'a>(&'a self, key: &K) -> &'a str
Resolves a string by its key. Only keys made by the current Rodeo may be used
§Panics
Panics if the key is out of bounds
§Example
use lasso::Rodeo;
let mut rodeo = Rodeo::default();
let key = rodeo.get_or_intern("Strings of things with wings and dings");
assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));
Sourcepub fn try_resolve<'a>(&'a self, key: &K) -> Option<&'a str>
pub fn try_resolve<'a>(&'a self, key: &K) -> Option<&'a str>
Resolves a string by its key, returning None
if it’s out of bounds. Only keys made by the
current Rodeo may be used
§Example
use lasso::Rodeo;
let mut rodeo = Rodeo::default();
let key = rodeo.get_or_intern("Strings of things with wings and dings");
assert_eq!(Some("Strings of things with wings and dings"), rodeo.try_resolve(&key));
Sourcepub unsafe fn resolve_unchecked<'a>(&'a self, key: &K) -> &'a str
pub unsafe fn resolve_unchecked<'a>(&'a self, key: &K) -> &'a str
Resolves a string by its key, without bounds checks
§Safety
The key must be valid for the current interner
§Example
use lasso::Rodeo;
let mut rodeo = Rodeo::default();
let key = rodeo.get_or_intern("Strings of things with wings and dings");
unsafe {
assert_eq!("Strings of things with wings and dings", rodeo.resolve_unchecked(&key));
}
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Gets the number of interned strings
§Example
use lasso::Rodeo;
let mut rodeo = Rodeo::default();
rodeo.get_or_intern("Documentation often has little hidden bits in it");
assert_eq!(rodeo.len(), 1);
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if there are no currently interned strings
§Example
use lasso::Rodeo;
let rodeo = Rodeo::default();
assert!(rodeo.is_empty());
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the current interner, invalidating all previously interned keys
§Example
use lasso::Rodeo;
let mut rodeo = Rodeo::default();
let key = rodeo.get_or_intern("Somewhere over the rainbow...");
// We can see that the interner currently contains one string
assert_eq!(rodeo.len(), 1);
// And that resolving that string works as expected
assert_eq!(rodeo.resolve(&key), "Somewhere over the rainbow...");
// But after we clear it...
rodeo.clear();
// We see it's now empty
assert_eq!(rodeo.len(), 0);
// And that resolving the previously interned string now returns nothing
assert_eq!(rodeo.try_resolve(&key), None);
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of strings that can be interned without a reallocation
§Example
use lasso::{Spur, Capacity, Rodeo};
let rodeo: Rodeo<Spur> = Rodeo::with_capacity(Capacity::for_strings(10));
assert_eq!(rodeo.capacity(), 10);
Sourcepub fn iter(&self) -> Iter<'_, K>
pub fn iter(&self) -> Iter<'_, K>
Returns an iterator over the interned strings and their key values
Sourcepub fn set_memory_limits(&mut self, memory_limits: MemoryLimits)
pub fn set_memory_limits(&mut self, memory_limits: MemoryLimits)
Set the Rodeo
’s maximum memory usage while in-flight
Note that setting the maximum memory usage to below the currently allocated memory will do nothing
Sourcepub fn current_memory_usage(&self) -> usize
pub fn current_memory_usage(&self) -> usize
Get the Rodeo
’s currently allocated memory
Sourcepub fn max_memory_usage(&self) -> usize
pub fn max_memory_usage(&self) -> usize
Get the Rodeo
’s current maximum of allocated memory
Sourcepub fn try_clone(&self) -> Result<Rodeo<K, S>, LassoError>
pub fn try_clone(&self) -> Result<Rodeo<K, S>, LassoError>
Attempts to clone a new Rodeo
from the current one, equivalent to Clone::clone
with the added option of error handling
Sourcepub fn try_clone_from(&mut self, source: &Rodeo<K, S>) -> Result<(), LassoError>
pub fn try_clone_from(&mut self, source: &Rodeo<K, S>) -> Result<(), LassoError>
Attempts to clone a new Rodeo
from source
while reusing the current Rodeo
’s buffers,
equivalent to Clone::clone_from
with the added option of error handling.
In the event that this function returns an error, self
is in an unspecified state
Trait Implementations§
Source§impl Clone for StringTable
impl Clone for StringTable
Source§impl Debug for StringTable
impl Debug for StringTable
Source§impl Deref for StringTable
impl Deref for StringTable
Source§impl DerefMut for StringTable
impl DerefMut for StringTable
Source§impl From<Rodeo<Spur, BuildHasherDefault<FxHasher>>> for StringTable
impl From<Rodeo<Spur, BuildHasherDefault<FxHasher>>> for StringTable
Auto Trait Implementations§
impl Freeze for StringTable
impl RefUnwindSafe for StringTable
impl Send for StringTable
impl Sync for StringTable
impl Unpin for StringTable
impl UnwindSafe for StringTable
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more