Struct Interner

Source
pub struct Interner<T, B = <T as DefaultBackendBuilder>::Backend, H = RandomState>
where T: Hash + Eq + PartialEq + ?Sized, H: BuildHasher, B: Backend<T>,
{ /* private fields */ }
Expand description

Interner

This struct is responsible for tracking objects and interning them.

§Example

use interns::*;

let mut interner = Interner::<str>::default();

let a = interner.get_or_intern("hello");
let b = interner.get_or_intern("world");
let c = interner.get_or_intern("hello");

let a_resolv = interner.resolve(a);
let b_resolv = interner.resolve(b);
let c_resolv = interner.resolve(c);

assert_eq!(a_resolv, Some("hello"));
assert_eq!(b_resolv, Some("world"));
assert_eq!(c_resolv, Some("hello"));

assert_eq!(a, c);
assert_ne!(a, b);
assert_ne!(b, c);

Implementations§

Source§

impl<T, B, H> Interner<T, B, H>
where T: Hash + Eq + PartialEq + ?Sized, H: BuildHasher + Default, B: Backend<T>,

Source

pub fn new() -> Self
where B: Default, H: Default,

Create a new Interner with a default backend and hasher

Source

pub fn with_hasher(hasher: H) -> Self
where B: Default,

Create a new Interner with a default backend and the given hasher

Source

pub fn with_backend(backend: B) -> Self
where H: Default,

Create a new Interner with a default hasher and the given backend

Source

pub fn with_backend_and_hasher(backend: B, hasher: H) -> Self

Create a new Interner with the given backend and hasher

Source

pub fn get_or_intern(&mut self, src: &T) -> B::Symbol

Turns a reference of T into the backend’s symbol

Source

pub fn resolve(&self, sym: B::Symbol) -> Option<&T>

Resolves the symbol into a reference of T

Source

pub fn len(&self) -> usize

Returns the number of elements currently interned

Source

pub fn is_empty(&self) -> bool

Returns true if the interner contains no elements

Source

pub fn capacity(&self) -> usize

Returns the capacity of the interner

Trait Implementations§

Source§

impl<T, B> Default for Interner<T, B>
where T: Hash + Eq + PartialEq + ?Sized, B: Backend<T> + Default,

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<T, B, H> Freeze for Interner<T, B, H>
where B: Freeze, H: Freeze, T: ?Sized,

§

impl<T, B, H> RefUnwindSafe for Interner<T, B, H>

§

impl<T, B, H> Send for Interner<T, B, H>
where B: Send, H: Send, <B as Backend<T>>::Symbol: Send, T: ?Sized,

§

impl<T, B, H> Sync for Interner<T, B, H>
where B: Sync, H: Sync, <B as Backend<T>>::Symbol: Sync, T: ?Sized,

§

impl<T, B, H> Unpin for Interner<T, B, H>
where B: Unpin, H: Unpin, <B as Backend<T>>::Symbol: Unpin, T: ?Sized,

§

impl<T, B, H> UnwindSafe for Interner<T, B, H>
where B: UnwindSafe, H: UnwindSafe, <B as Backend<T>>::Symbol: UnwindSafe, T: ?Sized,

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, 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.