Skip to main content

InlineHashMap

Struct InlineHashMap 

Source
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 is_empty(&self) -> bool

Returns true if the map contains no elements

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

If an equal key is already present, the stored key is retained and its value is replaced. The map’s length does not change.

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 duplicate of the value. Read more
1.0.0 (const: unstable) · 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> Freeze for InlineHashMap<K, V, N>
where InlineHashMapInner<K, V, N>: Freeze,

§

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

§

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

§

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

§

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

§

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

§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

Source§

type Error = !

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.