Struct StringTable

Source
pub struct StringTable(/* private fields */);

Implementations§

Source§

impl StringTable

Source

pub fn with_hasher(hash_builder: FxBuildHasher) -> Self

Methods from Deref<Target = Rodeo<Spur, FxBuildHasher>>§

Source

pub fn get_or_intern<T>(&mut self, val: T) -> K
where T: AsRef<str>,

Get the key for a string, interning it if it does not yet exist

§Panics

Panics if the key’s try_from_usize function fails. With the default keys, this means that you’ve interned more strings than it can handle. (For Spur this means that u32::MAX - 1 unique strings were interned)

§Example
use lasso::Rodeo;

let mut rodeo = Rodeo::default();

// Interned the string
let key = rodeo.get_or_intern("Strings of things with wings and dings");
assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));

// No string was interned, as it was already contained
let key = rodeo.get_or_intern("Strings of things with wings and dings");
assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));
Source

pub fn try_get_or_intern<T>(&mut self, val: T) -> Result<K, LassoError>
where T: AsRef<str>,

Get the key for a string, interning it if it does not yet exist

§Example
use lasso::Rodeo;

let mut rodeo = Rodeo::default();

// Interned the string
let key = rodeo.try_get_or_intern("Strings of things with wings and dings").unwrap();
assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));

// No string was interned, as it was already contained
let key = rodeo.try_get_or_intern("Strings of things with wings and dings").unwrap();
assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));
Source

pub fn get_or_intern_static(&mut self, string: &'static str) -> K

Get the key for a static string, interning it if it does not yet exist

This will not reallocate or copy the given string

§Panics

Panics if the key’s try_from_usize function fails. With the default keys, this means that you’ve interned more strings than it can handle. (For Spur this means that u32::MAX - 1 unique strings were interned)

§Example
use lasso::Rodeo;

let mut rodeo = Rodeo::default();

// Interned the string
let key = rodeo.get_or_intern_static("Strings of things with wings and dings");
assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));

// No string was interned, as it was already contained
let key = rodeo.get_or_intern_static("Strings of things with wings and dings");
assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));
Source

pub fn try_get_or_intern_static( &mut self, string: &'static str, ) -> Result<K, LassoError>

Get the key for a static string, interning it if it does not yet exist

This will not reallocate or copy the given string

§Example
use lasso::Rodeo;

let mut rodeo = Rodeo::default();

// Interned the string
let key = rodeo.try_get_or_intern_static("Strings of things with wings and dings").unwrap();
assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));

// No string was interned, as it was already contained
let key = rodeo.try_get_or_intern_static("Strings of things with wings and dings").unwrap();
assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));
Source

pub fn get<T>(&self, val: T) -> Option<K>
where T: AsRef<str>,

Get the key value of a string, returning None if it doesn’t exist

§Example
use lasso::Rodeo;

let mut rodeo = Rodeo::default();

let key = rodeo.get_or_intern("Strings of things with wings and dings");
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>,

Returns true if the given string has been interned

§Example
use lasso::Rodeo;

let mut rodeo = Rodeo::default();

let key = rodeo.get_or_intern("Strings of things with wings and dings");
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

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");
assert!(rodeo.contains_key(&key));

assert!(!rodeo.contains_key(&key_that_doesnt_exist));
Source

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

Resolves a string by its key. Only keys made by the current Rodeo may be used

§Panics

Panics if the key is out of bounds

§Example
use lasso::Rodeo;

let mut rodeo = Rodeo::default();

let key = rodeo.get_or_intern("Strings of things with wings and dings");
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>

Resolves a string by its key, returning None if it’s out of bounds. Only keys made by the current Rodeo may be used

§Example
use lasso::Rodeo;

let mut rodeo = Rodeo::default();

let key = rodeo.get_or_intern("Strings of things with wings and dings");
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

Resolves a string by its key, without bounds checks

§Safety

The key must be valid for 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");
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 lasso::Rodeo;

let mut rodeo = Rodeo::default();
rodeo.get_or_intern("Documentation often has little hidden bits in it");

assert_eq!(rodeo.len(), 1);
Source

pub fn is_empty(&self) -> bool

Returns true if there are no currently interned strings

§Example
use lasso::Rodeo;

let rodeo = Rodeo::default();
assert!(rodeo.is_empty());
Source

pub fn clear(&mut self)

Clears the current interner, invalidating all previously interned keys

§Example
use lasso::Rodeo;

let mut rodeo = Rodeo::default();
let key = rodeo.get_or_intern("Somewhere over the rainbow...");

// We can see that the interner currently contains one string
assert_eq!(rodeo.len(), 1);
// And that resolving that string works as expected
assert_eq!(rodeo.resolve(&key), "Somewhere over the rainbow...");

// But after we clear it...
rodeo.clear();

// We see it's now empty
assert_eq!(rodeo.len(), 0);
// And that resolving the previously interned string now returns nothing
assert_eq!(rodeo.try_resolve(&key), None);
Source

pub fn capacity(&self) -> usize

Returns the number of strings that can be interned without a reallocation

§Example
use lasso::{Spur, Capacity, Rodeo};

let rodeo: Rodeo<Spur> = Rodeo::with_capacity(Capacity::for_strings(10));
assert_eq!(rodeo.capacity(), 10);
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 set_memory_limits(&mut self, memory_limits: MemoryLimits)

Set the Rodeo’s maximum memory usage while in-flight

Note that setting the maximum memory usage to below the currently allocated memory will do nothing

Source

pub fn current_memory_usage(&self) -> usize

Get the Rodeo’s currently allocated memory

Source

pub fn max_memory_usage(&self) -> usize

Get the Rodeo’s current maximum of allocated memory

Source

pub fn try_clone(&self) -> Result<Rodeo<K, S>, LassoError>

Attempts to clone a new Rodeo from the current one, equivalent to Clone::clone with the added option of error handling

Source

pub fn try_clone_from(&mut self, source: &Rodeo<K, S>) -> Result<(), LassoError>

Attempts to clone a new Rodeo from source while reusing the current Rodeo’s buffers, equivalent to Clone::clone_from with the added option of error handling.

In the event that this function returns an error, self is in an unspecified state

Trait Implementations§

Source§

impl Clone for StringTable

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StringTable

Source§

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

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

impl Deref for StringTable

Source§

type Target = Rodeo<Spur, BuildHasherDefault<FxHasher>>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for StringTable

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl From<Rodeo<Spur, BuildHasherDefault<FxHasher>>> for StringTable

Source§

fn from(inner: Rodeo<Spur, FxBuildHasher>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.