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>
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 lasso2::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) -> bool
pub fn contains<T>(&self, val: T) -> bool
Returns true if the given string has been interned
§Example
use lasso2::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 lasso2::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 lasso2::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 lasso2::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 lasso2::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 lasso2::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 lasso2::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 lasso2::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<'de, K: Key, S: BuildHasher + Default> Deserialize<'de> for RodeoReader<K, S>
Available on crate feature serialize only.
impl<'de, K: Key, S: BuildHasher + Default> Deserialize<'de> for RodeoReader<K, S>
serialize only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
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,
Source§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§impl<K, S> PartialEq<RodeoReader<K, S>> for RodeoResolver<K>
impl<K, S> PartialEq<RodeoReader<K, S>> for RodeoResolver<K>
Source§impl<K, S> PartialEq<RodeoReader<K, S>> for ThreadedRodeo<K, S>
Available on crate feature multi-threaded and non-crate feature no-std only.
impl<K, S> PartialEq<RodeoReader<K, S>> for ThreadedRodeo<K, S>
multi-threaded and non-crate feature no-std only.Source§impl<K, S> PartialEq<RodeoResolver<K>> for RodeoReader<K, S>
impl<K, S> PartialEq<RodeoResolver<K>> for RodeoReader<K, S>
Source§impl<K, S> PartialEq for RodeoReader<K, S>
impl<K, S> PartialEq for RodeoReader<K, S>
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 keySource§impl<K, H> Serialize for RodeoReader<K, H>
Available on crate feature serialize only.
impl<K, H> Serialize for RodeoReader<K, H>
serialize only.