[][src]Struct lasso::ReadOnlyLasso

pub struct ReadOnlyLasso<K: Key = Cord, S: BuildHasher + Clone = RandomState> { /* fields omitted */ }

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]

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]

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

impl<K, S> Unpin for ReadOnlyLasso<K, S> where
    K: Unpin,
    S: Unpin

impl<K, S> UnwindSafe for ReadOnlyLasso<K, S> where
    K: UnwindSafe,
    S: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.