Struct VacantEntry

pub struct VacantEntry<'a, K, V> { /* private fields */ }

A view into a vacant entry in an [IndexMap][crate::IndexMap]. It is part of the Entry enum.

Implementations

impl<'a, K, V> VacantEntry<'a, K, V>

fn index(&self) -> usize

Return the index where a key-value pair may be inserted.

fn key(&self) -> &K

Gets a reference to the key that was used to find the entry.

fn into_key(self) -> K

Takes ownership of the key, leaving the entry vacant.

fn insert(self, value: V) -> &'a mut V

Inserts the entry's key and the given value into the map, and returns a mutable reference to the value.

Computes in O(1) time (amortized average).

fn insert_entry(self, value: V) -> OccupiedEntry<'a, K, V>

Inserts the entry's key and the given value into the map, and returns an OccupiedEntry.

Computes in O(1) time (amortized average).

fn insert_sorted(self, value: V) -> (usize, &'a mut V)
where
    K: Ord,

Inserts the entry's key and the given value into the map at its ordered position among sorted keys, and returns the new index and a mutable reference to the value.

If the existing keys are not already sorted, then the insertion index is unspecified (like slice::binary_search), but the key-value pair is inserted at that position regardless.

Computes in O(n) time (average).

fn insert_sorted_by<F>(self, value: V, cmp: F) -> (usize, &'a mut V)
where
    F: FnMut(&K, &V, &K, &V) -> Ordering,

Inserts the entry's key and the given value into the map at its ordered position among keys sorted by cmp, and returns the new index and a mutable reference to the value.

If the existing keys are not already sorted, then the insertion index is unspecified (like slice::binary_search), but the key-value pair is inserted at that position regardless.

Computes in O(n) time (average).

fn insert_sorted_by_key<B, F>(self, value: V, sort_key: F) -> (usize, &'a mut V)
where
    B: Ord,
    F: FnMut(&K, &V) -> B,

Inserts the entry's key and the given value into the map at its ordered position using a sort-key extraction function, and returns the new index and a mutable reference to the value.

If the existing keys are not already sorted, then the insertion index is unspecified (like slice::binary_search), but the key-value pair is inserted at that position regardless.

Computes in O(n) time (average).

fn shift_insert(self, index: usize, value: V) -> &'a mut V

Inserts the entry's key and the given value into the map at the given index, shifting others to the right, and returns a mutable reference to the value.

Panics if index is out of bounds.

Computes in O(n) time (average).

fn replace_index(self, index: usize) -> (K, OccupiedEntry<'a, K, V>)

Replaces the key at the given index with this entry's key, returning the old key and an OccupiedEntry for that index.

Panics if index is out of bounds.

Computes in O(1) time (average).

Trait Implementations

impl<K, V> MutableEntryKey for VacantEntry<'_, K, V>

type Key = K;
fn key_mut(&mut self) -> &mut Self::Key

impl<K: Debug, V> Debug for VacantEntry<'_, K, V>

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

Auto Trait Implementations

impl<'a, K, V> !UnwindSafe for VacantEntry<'a, K, V>

impl<'a, K, V> Freeze for VacantEntry<'a, K, V> where &'a mut Core<K, V>: Freeze, K: Freeze,

impl<'a, K, V> RefUnwindSafe for VacantEntry<'a, K, V> where &'a mut Core<K, V>: RefUnwindSafe, K: RefUnwindSafe,

impl<'a, K, V> Send for VacantEntry<'a, K, V> where &'a mut Core<K, V>: Send, K: Send,

impl<'a, K, V> Sync for VacantEntry<'a, K, V> where &'a mut Core<K, V>: Sync, K: Sync,

impl<'a, K, V> Unpin for VacantEntry<'a, K, V> where &'a mut Core<K, V>: Unpin, K: Unpin,

impl<'a, K, V> UnsafeUnpin for VacantEntry<'a, K, V> where &'a mut Core<K, V>: UnsafeUnpin, K: UnsafeUnpin,

Blanket Implementations

impl<T> Any for VacantEntry<'a, K, V> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for VacantEntry<'a, K, V> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for VacantEntry<'a, K, V> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> From<T> for VacantEntry<'a, K, V>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into<U> for VacantEntry<'a, K, V> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for VacantEntry<'a, K, V> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for VacantEntry<'a, K, V> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>