Struct 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>

Source

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 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"));
Source

pub fn contains<T>(&self, val: T) -> bool
where T: AsRef<str>, S: BuildHasher, K: Key,

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"));
Source

pub fn contains_key(&self, key: &K) -> bool
where 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));
Source

pub fn resolve<'a>(&'a self, key: &K) -> &'a str
where 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));
Source

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));
Source

pub unsafe fn resolve_unchecked<'a>(&'a self, key: &K) -> &'a str
where 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));
}
Source

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);
Source

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());
Source

pub fn iter(&self) -> Iter<'_, K>

Returns an iterator over the interned strings and their key values

Source

pub fn strings(&self) -> Strings<'_, K>

Returns an iterator over the interned strings

Source

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<K: Debug, S: Debug> Debug for RodeoReader<K, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, K: Key, S: BuildHasher + Default> Deserialize<'de> for RodeoReader<K, S>

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<K, S> Index<K> for RodeoReader<K, S>
where K: Key, S: BuildHasher,

Source§

type Output = str

The returned type after indexing.
Source§

fn index(&self, idx: K) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, K: Key, S> IntoIterator for &'a RodeoReader<K, S>

Source§

type Item = (K, &'a str)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, K>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<K, S> IntoResolver<K> for RodeoReader<K, S>
where K: Key, S: BuildHasher,

Source§

type Resolver = RodeoResolver<K>

The type of Resolver the reader will be converted into
Source§

fn into_resolver(self) -> Self::Resolver
where Self: 'static,

Consumes the current Reader and makes it into a Resolver, allowing contention-free access from multiple threads with the lowest possible memory consumption
Source§

impl<K, S> PartialEq<Rodeo<K, S>> for RodeoReader<K, S>

Source§

fn eq(&self, other: &Rodeo<K, S>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<K, S> PartialEq<RodeoReader<K, S>> for Rodeo<K, S>

Source§

fn eq(&self, other: &RodeoReader<K, S>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<K, S> PartialEq<RodeoReader<K, S>> for RodeoResolver<K>

Source§

fn eq(&self, other: &RodeoReader<K, S>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<K, S> PartialEq<RodeoResolver<K>> for RodeoReader<K, S>

Source§

fn eq(&self, other: &RodeoResolver<K>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<K, S> PartialEq for RodeoReader<K, S>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<K, S> Reader<K> for RodeoReader<K, S>
where K: Key, S: BuildHasher,

Source§

fn get(&self, val: &str) -> Option<K>

Get a key for the given string value if it exists
Source§

fn contains(&self, val: &str) -> bool

Returns true if the current interner contains the given string
Source§

impl<K, S> Resolver<K> for RodeoReader<K, S>
where K: Key,

Source§

fn resolve<'a>(&'a self, key: &K) -> &'a str

Resolves the given key into a string Read more
Source§

fn try_resolve<'a>(&'a self, key: &K) -> Option<&'a str>

Attempts to resolve the given key into a string, returning None if it cannot be found
Source§

unsafe fn resolve_unchecked<'a>(&'a self, key: &K) -> &'a str

Resolves a string by its key without preforming bounds checks Read more
Source§

fn contains_key(&self, key: &K) -> bool

Returns true if the current interner contains the given key
Source§

fn len(&self) -> usize

Gets the number of currently interned strings
Source§

fn is_empty(&self) -> bool

Returns true if there are no currently interned strings
Source§

impl<K, H> Serialize for RodeoReader<K, H>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<K, S> Eq for RodeoReader<K, S>

Source§

impl<K: Send, S: Send> Send for RodeoReader<K, S>

Source§

impl<K: Sync, S: Sync> Sync for RodeoReader<K, S>

Auto Trait Implementations§

§

impl<K = Spur, S = RandomState> !Freeze for RodeoReader<K, S>

§

impl<K, S> RefUnwindSafe for RodeoReader<K, S>

§

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

§

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

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,