pub struct InlineHashMap<K, V, const N: usize>(/* private fields */);
Expand description

Similar to InlineVec, this structure will use an array if it is small enough to live on the stack, otherwise it allocates a HashMap on the heap

Hashing can be slower than just iterating through an array if the array is small, which is where it makes most sense

Implementations§

source§

impl<K, V, const N: usize> InlineHashMap<K, V, N>
where K: Hash + Eq,

source

pub fn len(&self) -> usize

Returns the number of elements in the map

source

pub fn iter(&self) -> Box<dyn Iterator<Item = (&K, &V)> + '_>

Returns an iterator over the elements of this map

This function boxes the returned iterator because it can be either of two:

  • The iterator returned by HashMap::iter()
  • The iterator over a stack-allocated array
source

pub fn inline_parts_mut( &mut self ) -> Option<(&mut [MaybeUninit<(K, V)>; N], usize)>

If self is inlined, this returns the underlying raw parts that make up this InlineHashMap.

Only the first .1 elements are initialized.

source

pub fn to_map(&self) -> HashMap<K, V>
where K: Clone + Hash + Eq, V: Clone,

Copies self into a new HashMap<K, V>

source

pub fn is_heap_allocated(&self) -> bool

Checks whether this vector is allocated on the heap

source

pub fn insert(&mut self, key: K, value: V)

Inserts a new element into the map

source

pub fn remove(&mut self, key: &K) -> Option<V>

Removes an element from the map, and returns ownership over the value

source

pub fn get(&self, key: &K) -> Option<&V>

Returns a reference to the value corresponding to the key.

source

pub fn get_mut(&mut self, key: &K) -> Option<&mut V>

Returns a mutable reference to the value corresponding to the key.

source

pub fn contains_key(&self, key: &K) -> bool

Checks whether the map contains a value for the specified key.

Trait Implementations§

source§

impl<K: Clone, V: Clone, const N: usize> Clone for InlineHashMap<K, V, N>

source§

fn clone(&self) -> InlineHashMap<K, V, N>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<K: Debug, V: Debug, const N: usize> Debug for InlineHashMap<K, V, N>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K, V, const N: usize> RefUnwindSafe for InlineHashMap<K, V, N>

§

impl<K, V, const N: usize> Send for InlineHashMap<K, V, N>
where K: Send, V: Send,

§

impl<K, V, const N: usize> Sync for InlineHashMap<K, V, N>
where K: Sync, V: Sync,

§

impl<K, V, const N: usize> Unpin for InlineHashMap<K, V, N>
where K: Unpin, V: Unpin,

§

impl<K, V, const N: usize> UnwindSafe for InlineHashMap<K, V, N>
where K: UnwindSafe, V: 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> 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.