Skip to main content

InlineDictionary

Struct InlineDictionary 

Source
pub struct InlineDictionary<TKey, TValue> { /* private fields */ }
Expand description

A dictionary that holds one entry in place, up to six entries in a small array and more in a hash map.

The original restricts keys to reference types and compares them by reference while the dictionary holds its entries in place or in the array; here keys compare with == in every state, which is identity for the handle types of this crate.

Implementations§

Source§

impl<TKey: Clone + Eq + Hash, TValue: Default> InlineDictionary<TKey, TValue>

Source

pub fn new() -> Self

Source

pub fn add(&mut self, key: TKey, value: TValue)

Adds an entry.

Panics when the small array or the dictionary has the key already. As in the original, a dictionary that holds one entry in place does not test for it.

Source

pub fn set(&mut self, key: TKey, value: TValue)

Adds an entry or replaces its value.

Source

pub fn get(&self, key: &TKey) -> &TValue

The value of a key (the getter of the indexer).

Panics when the dictionary does not have the key.

Source

pub fn remove(&mut self, key: &TKey) -> bool

Source

pub fn clear(&mut self)

Removes every entry.

As in the original, the value of an entry that is held in place is kept and becomes the value of the next key that get_value_ref_or_add_default adds in place.

Source

pub fn has_entries(&self) -> bool

Source

pub fn try_get_value(&self, key: &TKey) -> Option<&TValue>

Source

pub fn get_value_ref_or_null_ref(&mut self, key: &TKey) -> Option<&mut TValue>

A reference to the value of a key, or None (the original’s null reference) when the dictionary does not have the key.

Source

pub fn get_value_ref_or_add_default(&mut self, key: TKey) -> (&mut TValue, bool)

A reference to the value of a key, which is added with the default value when the dictionary does not have it, and whether it existed.

Source

pub fn try_get_and_remove_value(&mut self, key: &TKey) -> Option<TValue>

Removes an entry and returns its value.

As in the original, an entry of a dictionary that has grown into a hash map is removed without its value being returned.

Source

pub fn get_and_remove(&mut self, key: &TKey) -> TValue

Removes an entry and returns its value.

Panics when try_get_and_remove_value returns nothing.

Source

pub fn get_enumerator(&self) -> InlineDictionaryEnumerator<'_, TKey, TValue> ⓘ

Trait Implementations§

Source§

impl<TKey: Clone + Eq + Hash, TValue: Default> Default for InlineDictionary<TKey, TValue>

Source§

fn default() -> Self

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

impl<'a, TKey: Clone + Eq + Hash, TValue: Default> IntoIterator for &'a InlineDictionary<TKey, TValue>

Source§

type Item = (&'a TKey, &'a TValue)

The type of the elements being iterated over.
Source§

type IntoIter = InlineDictionaryEnumerator<'a, TKey, TValue>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<TKey, TValue> Freeze for InlineDictionary<TKey, TValue>
where Data<TKey, TValue>: Freeze, TValue: Freeze,

§

impl<TKey, TValue> RefUnwindSafe for InlineDictionary<TKey, TValue>
where Data<TKey, TValue>: RefUnwindSafe, TValue: RefUnwindSafe,

§

impl<TKey, TValue> Send for InlineDictionary<TKey, TValue>
where Data<TKey, TValue>: Send, TValue: Send,

§

impl<TKey, TValue> Sync for InlineDictionary<TKey, TValue>
where Data<TKey, TValue>: Sync, TValue: Sync,

§

impl<TKey, TValue> Unpin for InlineDictionary<TKey, TValue>
where Data<TKey, TValue>: Unpin, TValue: Unpin,

§

impl<TKey, TValue> UnsafeUnpin for InlineDictionary<TKey, TValue>
where Data<TKey, TValue>: UnsafeUnpin, TValue: UnsafeUnpin,

§

impl<TKey, TValue> UnwindSafe for InlineDictionary<TKey, TValue>
where Data<TKey, TValue>: UnwindSafe, TValue: UnwindSafe,

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> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.