Enum Entry

pub 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) -> usize

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

fn insert_entry(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, 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, 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, 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) -> &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, f: F) -> Self
where
    F: FnOnce(&mut V),

Modifies the entry if it is occupied.

fn or_default(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).

Trait Implementations

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

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

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

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

Auto Trait Implementations

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

impl<'a, K, V> Freeze for Entry<'a, K, V> where OccupiedEntry<'a, K, V>: Freeze, VacantEntry<'a, K, V>: Freeze,

impl<'a, K, V> RefUnwindSafe for Entry<'a, K, V> where OccupiedEntry<'a, K, V>: RefUnwindSafe, VacantEntry<'a, K, V>: RefUnwindSafe,

impl<'a, K, V> Send for Entry<'a, K, V> where OccupiedEntry<'a, K, V>: Send, VacantEntry<'a, K, V>: Send,

impl<'a, K, V> Sync for Entry<'a, K, V> where OccupiedEntry<'a, K, V>: Sync, VacantEntry<'a, K, V>: Sync,

impl<'a, K, V> Unpin for Entry<'a, K, V> where OccupiedEntry<'a, K, V>: Unpin, VacantEntry<'a, K, V>: Unpin,

impl<'a, K, V> UnsafeUnpin for Entry<'a, K, V> where OccupiedEntry<'a, K, V>: UnsafeUnpin, VacantEntry<'a, K, V>: UnsafeUnpin,

Blanket Implementations

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

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

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into<U> for Entry<'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 Entry<'a, K, V> where U: Into<T>,

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

impl<T, U> TryInto<U> for Entry<'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>