pub struct INTERN { /* private fields */ }Methods from Deref<Target = ThreadedRodeo>§
Sourcepub fn get_or_intern<T>(&self, val: T) -> K
pub fn get_or_intern<T>(&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::ThreadedRodeo;
let rodeo = ThreadedRodeo::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>(&self, val: T) -> Result<K, LassoError>
pub fn try_get_or_intern<T>(&self, val: T) -> Result<K, LassoError>
Get the key for a string, interning it if it does not yet exist
§Example
use lasso::ThreadedRodeo;
let rodeo = ThreadedRodeo::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 get_or_intern_static(&self, string: &'static str) -> K
pub fn get_or_intern_static(&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 but will instead just store it
§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::ThreadedRodeo;
let mut rodeo = ThreadedRodeo::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(
&self,
string: &'static str,
) -> Result<K, LassoError>
pub fn try_get_or_intern_static( &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 and copy the given string but will instead just store it
§Example
use lasso::ThreadedRodeo;
let mut rodeo = ThreadedRodeo::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::ThreadedRodeo;
let rodeo = ThreadedRodeo::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::ThreadedRodeo;
let rodeo = ThreadedRodeo::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::ThreadedRodeo;
let mut rodeo = ThreadedRodeo::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 ThreadedRodeo may be used
§Panics
Panics if the key is out of bounds
§Example
use lasso::ThreadedRodeo;
let rodeo = ThreadedRodeo::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 is out of bounds. Only keys made by the current
ThreadedRodeo may be used
§Example
use lasso::ThreadedRodeo;
let rodeo = ThreadedRodeo::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 fn len(&self) -> usize
pub fn len(&self) -> usize
Gets the number of interned strings
§Example
use lasso::ThreadedRodeo;
let rodeo = ThreadedRodeo::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::ThreadedRodeo;
let rodeo = ThreadedRodeo::default();
assert!(rodeo.is_empty());Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of strings that can be interned without a reallocation
This is an unreliable measurement since the underlying hashmap is unreliable in its capacity measurement
§Example
use lasso::{Spur, Capacity, ThreadedRodeo};
let rodeo: ThreadedRodeo<Spur> = ThreadedRodeo::with_capacity(Capacity::for_strings(10));
assert_eq!(rodeo.capacity(), 10);Sourcepub fn iter(&self) -> Iter<'_, K, S>
pub fn iter(&self) -> Iter<'_, K, S>
Returns an iterator over the interned strings and their key values
Sourcepub fn set_memory_limits(&self, memory_limits: MemoryLimits)
pub fn set_memory_limits(&self, memory_limits: MemoryLimits)
Set the ThreadedRodeo’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 ThreadedRodeo’s currently allocated memory
Sourcepub fn max_memory_usage(&self) -> usize
pub fn max_memory_usage(&self) -> usize
Get the ThreadedRodeo’s current maximum of allocated memory
Trait Implementations§
Source§impl Deref for INTERN
impl Deref for INTERN
Source§type Target = ThreadedRodeo
type Target = ThreadedRodeo
Source§fn deref(&self) -> &ThreadedRodeo
fn deref(&self) -> &ThreadedRodeo
impl LazyStatic for INTERN
Auto Trait Implementations§
impl Freeze for INTERN
impl RefUnwindSafe for INTERN
impl Send for INTERN
impl Sync for INTERN
impl Unpin for INTERN
impl UnwindSafe for INTERN
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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