pub struct Interner<T: ?Sized, S = RandomState> { /* private fields */ }
Expand description

An interner based on a HashSet. See the crate-level docs for more.

Implementations§

source§

impl<T: Eq + Hash + ?Sized, S: BuildHasher> Interner<T, S>

source

pub fn intern<R>(&self, t: R) -> Interned<'_, T>where
    R: Borrow<T> + Into<Box<T>>,

Intern an item into the interner.

Takes borrowed or heap-allocated items. If the item has not been previously interned, it will be Into::intoed a Box on the heap and cached. Notably, if you give this fn a String or Vec, the allocation will be shrunk to fit.

Note that the interner may need to reallocate to make space for the new reference, just the same as a HashSet would. This cost is amortized to O(1) as it is in other standard library collections.

If you have an owned item (especially if it has a cheap transformation to Box) and no longer need the ownership, pass it in directly. Otherwise, pass in a reference.

See get for more about the interned symbol.

source

pub fn get(&self, t: &T) -> Option<Interned<'_, T>>

Get an interned reference out of this interner.

The returned reference is bound to the lifetime of the borrow used for this method. This guarantees that the returned reference will live no longer than this interner does.

source§

impl<T: ?Sized> Interner<T>

source

pub fn new() -> Self

Create an empty interner.

The backing set is initially created with a capacity of 0, so it will not allocate until it is first inserted into.

source

pub fn with_capacity(capacity: usize) -> Self

Create an empty interner with the specified capacity.

The interner will be able to hold at least capacity items without reallocating. If capacity is 0, the interner will not initially allocate.

source§

impl<T: ?Sized, H: BuildHasher> Interner<T, H>

Constructors to control the backing HashSet’s hash function

source

pub fn with_hasher(hasher: H) -> Self

Create an empty interner which will use the given hasher to hash the values.

The interner is also created with the default capacity.

source

pub fn with_capacity_and_hasher(capacity: usize, hasher: H) -> Self

Create an empty interner with the specified capacity, using hasher to hash the values.

The interner will be able to hold at least capacity items without reallocating. If capacity is 0, the interner will not initially allocate.

Trait Implementations§

source§

impl<T: Debug + ?Sized, S: Debug> Debug for Interner<T, S>

source§

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

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

impl<T: ?Sized, S: Default> Default for Interner<T, S>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T: ?Sized, S> RefUnwindSafe for Interner<T, S>

§

impl<T: ?Sized, S> Send for Interner<T, S>where
    S: Send,
    T: Send,

§

impl<T: ?Sized, S> Sync for Interner<T, S>where
    S: Send + Sync,
    T: Send + Sync,

§

impl<T: ?Sized, S> Unpin for Interner<T, S>where
    S: Unpin,

§

impl<T: ?Sized, S> UnwindSafe for Interner<T, S>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.