INTERN

Struct INTERN 

Source
pub struct INTERN { /* private fields */ }

Methods from Deref<Target = ThreadedRodeo>§

Source

pub fn get_or_intern<T>(&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::ThreadedRodeo;

let rodeo = ThreadedRodeo::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>(&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::ThreadedRodeo;

let rodeo = ThreadedRodeo::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 get_or_intern_static(&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 but will instead just store it

§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::ThreadedRodeo;

let mut rodeo = ThreadedRodeo::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( &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 and copy the given string but will instead just store it

§Example
use lasso::ThreadedRodeo;

let mut rodeo = ThreadedRodeo::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::ThreadedRodeo;

let rodeo = ThreadedRodeo::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::ThreadedRodeo;

let rodeo = ThreadedRodeo::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::ThreadedRodeo;

let mut rodeo = ThreadedRodeo::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 ThreadedRodeo may be used

§Panics

Panics if the key is out of bounds

§Example
use lasso::ThreadedRodeo;

let rodeo = ThreadedRodeo::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 is out of bounds. Only keys made by the current ThreadedRodeo may be used

§Example
use lasso::ThreadedRodeo;

let rodeo = ThreadedRodeo::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 fn len(&self) -> usize

Gets the number of interned strings

§Example
use lasso::ThreadedRodeo;

let rodeo = ThreadedRodeo::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::ThreadedRodeo;

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

pub fn capacity(&self) -> usize

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

This is an unreliable measurement since the underlying hashmap is unreliable in its capacity measurement

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

let rodeo: ThreadedRodeo<Spur> = ThreadedRodeo::with_capacity(Capacity::for_strings(10));
assert_eq!(rodeo.capacity(), 10);
Source

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

Returns an iterator over the interned strings and their key values

Source

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

Returns an iterator over the interned strings

Source

pub fn set_memory_limits(&self, memory_limits: MemoryLimits)

Set the ThreadedRodeo’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 ThreadedRodeo’s currently allocated memory

Source

pub fn max_memory_usage(&self) -> usize

Get the ThreadedRodeo’s current maximum of allocated memory

Trait Implementations§

Source§

impl Deref for INTERN

Source§

type Target = ThreadedRodeo

The resulting type after dereferencing.
Source§

fn deref(&self) -> &ThreadedRodeo

Dereferences the value.
Source§

impl LazyStatic for INTERN

Auto Trait Implementations§

§

impl Freeze for INTERN

§

impl RefUnwindSafe for INTERN

§

impl Send for INTERN

§

impl Sync for INTERN

§

impl Unpin for INTERN

§

impl UnwindSafe for INTERN

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more