Enum Entry

enum Entry<'a, K, V>

Entry for an existing key-value pair in an [IndexMap][crate::IndexMap] or a vacant location to insert one.

Variants

Occupied(OccupiedEntry<'a, K, V>)

Existing slot with equivalent key.

Vacant(VacantEntry<'a, K, V>)

Vacant slot (no equivalent key in the map).

Implementations

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

fn index(self: &Self) -> usize

Return the index where the key-value pair exists or will be inserted.

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

Sets the value of the entry (after inserting if vacant), and returns an OccupiedEntry.

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

fn or_insert(self: Self, default: V) -> &'a mut V

Inserts the given default value in the entry if it is vacant and returns a mutable reference to it. Otherwise a mutable reference to an already existent value is returned.

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

fn or_insert_with<F>(self: Self, call: F) -> &'a mut V
where
    F: FnOnce() -> V

Inserts the result of the call function in the entry if it is vacant and returns a mutable reference to it. Otherwise a mutable reference to an already existent value is returned.

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

fn or_insert_with_key<F>(self: Self, call: F) -> &'a mut V
where
    F: FnOnce(&K) -> V

Inserts the result of the call function with a reference to the entry's key if it is vacant, and returns a mutable reference to the new value. Otherwise a mutable reference to an already existent value is returned.

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

fn key(self: &Self) -> &K

Gets a reference to the entry's key, either within the map if occupied, or else the new key that was used to find the entry.

fn and_modify<F>(self: Self, f: F) -> Self
where
    F: FnOnce(&mut V)

Modifies the entry if it is occupied.

fn or_default(self: Self) -> &'a mut V
where
    V: Default

Inserts a default-constructed value in the entry if it is vacant and returns a mutable reference to it. Otherwise a mutable reference to an already existent value is returned.

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

impl<'a, K, V> Freeze for Entry<'a, K, V>

impl<'a, K, V> RefUnwindSafe for Entry<'a, K, V>

impl<'a, K, V> Send for Entry<'a, K, V>

impl<'a, K, V> Sync for Entry<'a, K, V>

impl<'a, K, V> Unpin for Entry<'a, K, V>

impl<'a, K, V> UnsafeUnpin for Entry<'a, K, V>

impl<'a, K, V> UnwindSafe for Entry<'a, K, V>

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

fn key_mut(self: &mut Self) -> &mut <Self as >::Key

impl<K: fmt::Debug, V: fmt::Debug> Debug for Entry<'_, K, V>

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

impl<T> Any for Entry<'a, K, V>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Entry<'a, K, V>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Entry<'a, K, V>

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

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

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for Entry<'a, K, V>

fn into(self: 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 for Entry<'a, K, V>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Entry<'a, K, V>

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