Struct lasso::RodeoReader
source · pub struct RodeoReader<K = Spur, S = RandomState> { /* private fields */ }
Expand description
A read-only view of a Rodeo
or ThreadedRodeo
that allows contention-free access to interned strings,
both key to string resolution and string to key lookups
The key and hasher types are the same as the Rodeo
or ThreadedRodeo
that created it, can be acquired with the
into_reader
methods.
Implementations§
source§impl<K, S> RodeoReader<K, S>
impl<K, S> RodeoReader<K, S>
sourcepub fn get<T>(&self, val: T) -> Option<K>where
T: AsRef<str>,
S: BuildHasher,
K: Key,
pub fn get<T>(&self, val: T) -> Option<K>where
T: AsRef<str>,
S: BuildHasher,
K: Key,
Get the key value of a string, returning None
if it doesn’t exist
Example
use lasso::Rodeo;
// ThreadedRodeo is interchangeable for Rodeo here
let mut rodeo = Rodeo::default();
let key = rodeo.get_or_intern("Strings of things with wings and dings");
let rodeo = rodeo.into_reader();
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) -> boolwhere
T: AsRef<str>,
S: BuildHasher,
K: Key,
pub fn contains<T>(&self, val: T) -> boolwhere
T: AsRef<str>,
S: BuildHasher,
K: Key,
Returns true
if the given string has been interned
Example
use lasso::Rodeo;
// ThreadedRodeo is interchangeable for Rodeo here
let mut rodeo = Rodeo::default();
let key = rodeo.get_or_intern("Strings of things with wings and dings");
let rodeo = rodeo.into_reader();
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) -> boolwhere
K: Key,
pub fn contains_key(&self, key: &K) -> boolwhere
K: Key,
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");
let rodeo = rodeo.into_reader();
assert!(rodeo.contains_key(&key));
assert!(!rodeo.contains_key(&key_that_doesnt_exist));
sourcepub fn resolve<'a>(&'a self, key: &K) -> &'a strwhere
K: Key,
pub fn resolve<'a>(&'a self, key: &K) -> &'a strwhere
K: Key,
Resolves a string by its key. Only keys made by the current Resolver or the creator of the current Resolver may be used
Panics
Panics if the key is out of bounds
Example
use lasso::Rodeo;
// ThreadedRodeo is interchangeable for Rodeo here
let mut rodeo = Rodeo::default();
let key = rodeo.get_or_intern("Strings of things with wings and dings");
let rodeo = rodeo.into_resolver();
assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));
sourcepub fn try_resolve<'a>(&'a self, key: &K) -> Option<&'a str>where
K: Key,
pub fn try_resolve<'a>(&'a self, key: &K) -> Option<&'a str>where
K: Key,
Resolves a string by its key, returning None
if the key is out of bounds. Only keys
made by the current Resolver or the creator of the current Resolver may be used
Example
use lasso::Rodeo;
// ThreadedRodeo is interchangeable for Rodeo here
let mut rodeo = Rodeo::default();
let key = rodeo.get_or_intern("Strings of things with wings and dings");
let rodeo = rodeo.into_resolver();
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 strwhere
K: Key,
pub unsafe fn resolve_unchecked<'a>(&'a self, key: &K) -> &'a strwhere
K: Key,
Resolves a string by its key without bounds checks
Safety
The key must be valid for the current Reader
Example
use lasso::Rodeo;
// ThreadedRodeo is interchangeable for Rodeo here
let mut rodeo = Rodeo::default();
let key = rodeo.get_or_intern("Strings of things with wings and dings");
let rodeo = rodeo.into_resolver();
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;
// ThreadedRodeo is interchangeable for Rodeo here
let mut rodeo = Rodeo::default();
rodeo.get_or_intern("Documentation often has little hidden bits in it");
let rodeo = rodeo.into_reader();
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;
// ThreadedRodeo is interchangeable for Rodeo here
let rodeo = Rodeo::default();
let rodeo = rodeo.into_reader();
assert!(rodeo.is_empty());
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 into_resolver(self) -> RodeoResolver<K>
pub fn into_resolver(self) -> RodeoResolver<K>
Consumes the current rodeo and makes it into a RodeoResolver
, allowing
contention-free access from multiple threads with the lowest possible memory consumption
Example
use lasso::Rodeo;
// ThreadedRodeo is interchangeable for Rodeo here
let mut rodeo = Rodeo::default();
let key = rodeo.get_or_intern("Appear weak when you are strong, and strong when you are weak.");
let reader_rodeo = rodeo.into_reader();
let resolver_rodeo = reader_rodeo.into_resolver();
assert_eq!(
"Appear weak when you are strong, and strong when you are weak.",
resolver_rodeo.resolve(&key),
);
Trait Implementations§
source§impl<K, S> Index<K> for RodeoReader<K, S>where
K: Key,
S: BuildHasher,
impl<K, S> Index<K> for RodeoReader<K, S>where
K: Key,
S: BuildHasher,
source§impl<'a, K: Key, S> IntoIterator for &'a RodeoReader<K, S>
impl<'a, K: Key, S> IntoIterator for &'a RodeoReader<K, S>
source§impl<K, S> IntoResolver<K> for RodeoReader<K, S>where
K: Key,
S: BuildHasher,
impl<K, S> IntoResolver<K> for RodeoReader<K, S>where
K: Key,
S: BuildHasher,
§type Resolver = RodeoResolver<K>
type Resolver = RodeoResolver<K>
Resolver
the reader will be converted intosource§impl<K, S> PartialEq<Rodeo<K, S>> for RodeoReader<K, S>
impl<K, S> PartialEq<Rodeo<K, S>> for RodeoReader<K, S>
source§impl<K, S> PartialEq<RodeoReader<K, S>> for Rodeo<K, S>
impl<K, S> PartialEq<RodeoReader<K, S>> for Rodeo<K, S>
source§fn eq(&self, other: &RodeoReader<K, S>) -> bool
fn eq(&self, other: &RodeoReader<K, S>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<K, S> PartialEq<RodeoReader<K, S>> for RodeoReader<K, S>
impl<K, S> PartialEq<RodeoReader<K, S>> for RodeoReader<K, S>
source§impl<K, S> PartialEq<RodeoReader<K, S>> for RodeoResolver<K>
impl<K, S> PartialEq<RodeoReader<K, S>> for RodeoResolver<K>
source§fn eq(&self, other: &RodeoReader<K, S>) -> bool
fn eq(&self, other: &RodeoReader<K, S>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<K, S> PartialEq<RodeoReader<K, S>> for ThreadedRodeo<K, S>where
K: Eq + Hash + Key,
S: Clone + BuildHasher,
impl<K, S> PartialEq<RodeoReader<K, S>> for ThreadedRodeo<K, S>where
K: Eq + Hash + Key,
S: Clone + BuildHasher,
source§fn eq(&self, other: &RodeoReader<K, S>) -> bool
fn eq(&self, other: &RodeoReader<K, S>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<K, S> PartialEq<RodeoResolver<K>> for RodeoReader<K, S>
impl<K, S> PartialEq<RodeoResolver<K>> for RodeoReader<K, S>
source§fn eq(&self, other: &RodeoResolver<K>) -> bool
fn eq(&self, other: &RodeoResolver<K>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<K, S> Reader<K> for RodeoReader<K, S>where
K: Key,
S: BuildHasher,
impl<K, S> Reader<K> for RodeoReader<K, S>where
K: Key,
S: BuildHasher,
source§impl<K, S> Resolver<K> for RodeoReader<K, S>where
K: Key,
impl<K, S> Resolver<K> for RodeoReader<K, S>where
K: Key,
source§fn try_resolve<'a>(&'a self, key: &K) -> Option<&'a str>
fn try_resolve<'a>(&'a self, key: &K) -> Option<&'a str>
None
if it cannot be foundsource§unsafe fn resolve_unchecked<'a>(&'a self, key: &K) -> &'a str
unsafe fn resolve_unchecked<'a>(&'a self, key: &K) -> &'a str
source§fn contains_key(&self, key: &K) -> bool
fn contains_key(&self, key: &K) -> bool
true
if the current interner contains the given key