[−][src]Struct lasso::ReadOnlyLasso
A read-only view of a Lasso
that allows contention-free access to interned strings
Made with the Lasso::into_read_only
method, the key and hasher types default to the ones used by
the Lasso
that created it
Methods
impl<K: Key, S: BuildHasher + Clone> ReadOnlyLasso<K, S>
[src]
pub fn get<T>(&self, val: T) -> Option<K> where
T: AsRef<str>,
[src]
T: AsRef<str>,
Get the key value of a string, returning None
if it doesn't exist
Example
use lasso::{Cord, Lasso}; let lasso = Lasso::default(); let key = lasso.intern("Strings of things with wings and dings"); let lasso = lasso.into_read_only(); assert_eq!(Some(key), lasso.get("Strings of things with wings and dings")); assert_eq!(None, lasso.get("This string isn't interned"));
pub fn resolve<'a>(&'a self, key: &K) -> &'a str
[src]
Resolves a string by its key
Safety
Safety relies on the given Key
's adherence to symmetry, if the key gives bad indexes then it will cause UB.
With that in mind, never use any key not directly provided by the interner
Example
use lasso::{Cord, Key, Lasso}; let lasso = Lasso::default(); let key = lasso.intern("Strings of things with wings and dings"); let lasso = lasso.into_read_only(); assert_eq!("Strings of things with wings and dings", lasso.resolve(&key));
pub fn len(&self) -> usize
[src]
Gets the number of interned strings
Example
use lasso::Lasso; let lasso = Lasso::default(); lasso.intern("Documentation often has little hidden bits in it"); let lasso = lasso.into_read_only(); assert_eq!(lasso.len(), 1);
pub fn is_empty(&self) -> bool
[src]
Returns true
if there are no currently interned strings
Example
use lasso::Lasso; let lasso = Lasso::default(); let lasso = lasso.into_read_only(); assert!(lasso.is_empty());
#[must_use]pub fn into_resolver(self) -> ResolverLasso<K>
[src]
Consumes the current ReadOnlyLasso, making it into a ResolverLasso
, allowing
contention-free access from multiple threads with the lowest possible memory consumption
Example
use lasso::Lasso; let lasso = Lasso::default(); let key = lasso.intern("Appear weak when you are strong, and strong when you are weak."); let read_only_lasso = lasso.into_read_only(); let resolver_lasso = read_only_lasso.into_resolver(); assert_eq!( "Appear weak when you are strong, and strong when you are weak.", resolver_lasso.resolve(&key), );
Trait Implementations
impl<K, S> Clone for ReadOnlyLasso<K, S> where
K: Key,
S: BuildHasher + Clone,
[src]
K: Key,
S: BuildHasher + Clone,
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<K: Debug + Key, S: Debug + BuildHasher + Clone> Debug for ReadOnlyLasso<K, S>
[src]
impl<K: Key, S: BuildHasher + Clone> Drop for ReadOnlyLasso<K, S>
[src]
Deallocate the leaked strings interned by ReadOnlyLasso
impl<K: Key, S: BuildHasher + Clone> Send for ReadOnlyLasso<K, S>
[src]
impl<K: Key, S: BuildHasher + Clone> Sync for ReadOnlyLasso<K, S>
[src]
Auto Trait Implementations
impl<K, S> RefUnwindSafe for ReadOnlyLasso<K, S> where
K: RefUnwindSafe,
S: RefUnwindSafe,
K: RefUnwindSafe,
S: RefUnwindSafe,
impl<K, S> Unpin for ReadOnlyLasso<K, S> where
K: Unpin,
S: Unpin,
K: Unpin,
S: Unpin,
impl<K, S> UnwindSafe for ReadOnlyLasso<K, S> where
K: UnwindSafe,
S: UnwindSafe,
K: UnwindSafe,
S: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,