Struct symtern::Pool
[−]
[src]
pub struct Pool<T: ?Sized, I = usize> where
T: ToOwned + Eq + Hash,
T::Owned: Eq + Hash,
I: SymbolId, { /* fields omitted */ }
Simple hash-based interner generic over both the type of interned values and the type used to represent symbol IDs.
Pool
can intern any type that implements ToOwned
, Eq
, and Hash
,
where its owned type (ToOwned::Owned
) also implements Eq
and Hash
.
use symtern::prelude::*; use symtern::Pool; #[derive(Clone, Eq, PartialEq, Hash)] struct WibbleWobble { whee: Vec<u32> } let mut pool = Pool::<_,u8>::new(); assert!(pool.intern(&WibbleWobble{whee: vec![1, 2, 3, 4, 5]}).is_ok());
Methods
impl<T: ?Sized, I> Pool<T, I> where
T: ToOwned + Eq + Hash,
T::Owned: Eq + Hash,
I: SymbolId,
[src]
T: ToOwned + Eq + Hash,
T::Owned: Eq + Hash,
I: SymbolId,
fn new() -> Self
Create a new, empty Pool
instance.
Trait Implementations
impl<T: Debug + ?Sized, I: Debug> Debug for Pool<T, I> where
T: ToOwned + Eq + Hash,
T::Owned: Eq + Hash,
I: SymbolId,
T::Owned: Debug,
[src]
T: ToOwned + Eq + Hash,
T::Owned: Eq + Hash,
I: SymbolId,
T::Owned: Debug,
impl<T: ?Sized, I> Clone for Pool<T, I> where
T: ToOwned + Eq + Hash,
T::Owned: Eq + Hash + Clone,
I: SymbolId,
[src]
T: ToOwned + Eq + Hash,
T::Owned: Eq + Hash + Clone,
I: SymbolId,
fn clone(&self) -> Self
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<'a, T: ?Sized, I> Len for Pool<T, I> where
T: ToOwned + Eq + Hash,
T::Owned: Eq + Hash,
I: SymbolId,
[src]
T: ToOwned + Eq + Hash,
T::Owned: Eq + Hash,
I: SymbolId,
fn len(&self) -> usize
Get the number of entries contained in the pool.
fn is_empty(&self) -> bool
Check if the pool is "empty", i.e. has zero stored values.
fn is_full(&self) -> bool
Check if the number of interned symbols has reached the maximum allowed for the pool's ID type.
impl<T: ?Sized, I> Default for Pool<T, I> where
T: ToOwned + Eq + Hash,
T::Owned: Eq + Hash,
I: SymbolId,
[src]
T: ToOwned + Eq + Hash,
T::Owned: Eq + Hash,
I: SymbolId,
impl<'a, T: ?Sized, I> Intern for &'a mut Pool<T, I> where
I: SymbolId,
T: ToOwned + Eq + Hash,
T::Owned: Eq + Hash + Borrow<T>,
[src]
I: SymbolId,
T: ToOwned + Eq + Hash,
T::Owned: Eq + Hash + Borrow<T>,
type Input = T
Type of value accepted by intern
.
type Symbol = Sym<I>
Type used to represent interned values.
fn intern(self, value: &Self::Input) -> Result<Self::Symbol>
Fetch the symbol that corresponds to the given value. If the value does not map to any existing symbol, create and return a new one. This method may return an error if the interner encounters any error while storing the value. Read more
impl<'a, T: ?Sized, I> Resolve for &'a Pool<T, I> where
T: ToOwned + Eq + Hash,
T::Owned: Eq + Hash + Borrow<T>,
I: SymbolId,
[src]
T: ToOwned + Eq + Hash,
T::Owned: Eq + Hash + Borrow<T>,
I: SymbolId,
type Input = <&'a mut Pool<T, I> as Intern>::Symbol
Type passed to the resolve
method.
type Output = &'a T
Type stored by the interner and made available with resolve
.
fn resolve(self, s: Self::Input) -> Result<Self::Output>
Look up and return a reference to the value represented by a symbol, or an error if the symbol was not found. Read more
impl<'a, T: ?Sized, I> ResolveUnchecked for &'a Pool<T, I> where
T: ToOwned + Eq + Hash,
T::Owned: Eq + Hash + Borrow<T>,
I: SymbolId,
[src]
T: ToOwned + Eq + Hash,
T::Owned: Eq + Hash + Borrow<T>,
I: SymbolId,
unsafe fn resolve_unchecked(self, symbol: Self::Input) -> Self::Output
Resolve the given symbol into its referent, bypassing any validity checks. Read more