pub enum Entry<'map, Key, Value, State = RandomState> {
    Occupied(OccupiedEntry<'map, Key, Value>),
    Vacant(VacantEntry<'map, Key, Value, State>),
}
Expand description

A view into a single entry in the multimap, which may either be vacant or occupied.

Variants§

§

Occupied(OccupiedEntry<'map, Key, Value>)

An occupied entry associated with one or more values.

§

Vacant(VacantEntry<'map, Key, Value, State>)

A vacant entry with no associated values.

Implementations§

source§

impl<'map, Key, Value, State> Entry<'map, Key, Value, State>
where Key: Eq + Hash, State: BuildHasher,

source

pub fn and_modify<Function>(self, function: Function) -> Self
where Function: FnOnce(&mut Value),

Calls the given function with a mutable reference to the first value of this entry, by insertion order, if it is vacant, otherwise this function is a no-op.

§Examples
use ordered_multimap::ListOrderedMultimap;

let mut map = ListOrderedMultimap::new();

map.entry("key")
    .and_modify(|value| *value += 1)
    .or_insert(42);
assert_eq!(map.get(&"key"), Some(&42));

map.entry("key")
    .and_modify(|value| *value += 1)
    .or_insert(42);
assert_eq!(map.get(&"key"), Some(&43));
source

pub fn or_insert(self, value: Value) -> &'map mut Value

If the entry is vacant, the given value will be inserted into it and a mutable reference to that value will be returned. Otherwise, a mutable reference to the first value, by insertion order, will be returned.

§Examples
use ordered_multimap::ListOrderedMultimap;

let mut map = ListOrderedMultimap::new();
map.insert("key", "value1");

let value = map.entry("key").or_insert("value2");
assert_eq!(value, &"value1");

let value = map.entry("key2").or_insert("value2");
assert_eq!(value, &"value2");
source

pub fn or_insert_entry(self, value: Value) -> OccupiedEntry<'map, Key, Value>

If the entry is vacant, the given value will be inserted into it and the new occupied entry will be returned. Otherwise, the existing occupied entry will be returned.

§Examples
use ordered_multimap::ListOrderedMultimap;

let mut map = ListOrderedMultimap::new();
map.insert("key", "value1");

let entry = map.entry("key").or_insert_entry("value2");
assert_eq!(entry.into_mut(), &"value1");

let entry = map.entry("key2").or_insert_entry("value2");
assert_eq!(entry.into_mut(), &"value2");
source

pub fn or_insert_with<Function>(self, function: Function) -> &'map mut Value
where Function: FnOnce() -> Value,

If the entry is vacant, the value returned from the given function will be inserted into it and a mutable reference to that value will be returned. Otherwise, a mutable reference to the first value, by insertion order, will be returned.

§Examples
use ordered_multimap::ListOrderedMultimap;

let mut map = ListOrderedMultimap::new();
map.insert("key", "value1");

let value = map.entry("key").or_insert_with(|| "value2");
assert_eq!(value, &"value1");

let value = map.entry("key2").or_insert_with(|| "value2");
assert_eq!(value, &"value2");
source

pub fn or_insert_with_entry<Function>( self, function: Function ) -> OccupiedEntry<'map, Key, Value>
where Function: FnOnce() -> Value,

If the entry is vacant, the value returned from the given function will be inserted into it and the new occupied entry will be returned. Otherwise, the existing occupied entry will be returned.

§Examples
use ordered_multimap::ListOrderedMultimap;

let mut map = ListOrderedMultimap::new();
map.insert("key", "value1");

let entry = map.entry("key").or_insert_with_entry(|| "value2");
assert_eq!(entry.into_mut(), &"value1");

let entry = map.entry("key2").or_insert_with_entry(|| "value2");
assert_eq!(entry.into_mut(), &"value2");

Trait Implementations§

source§

impl<Key, Value, State> Debug for Entry<'_, Key, Value, State>
where Key: Debug, State: BuildHasher, Value: Debug,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'map, Key, Value, State> Freeze for Entry<'map, Key, Value, State>
where Key: Freeze,

§

impl<'map, Key, Value, State> RefUnwindSafe for Entry<'map, Key, Value, State>
where Key: RefUnwindSafe, State: RefUnwindSafe, Value: RefUnwindSafe,

§

impl<'map, Key, Value, State> Send for Entry<'map, Key, Value, State>
where Key: Send, State: Sync, Value: Send,

§

impl<'map, Key, Value, State> Sync for Entry<'map, Key, Value, State>
where Key: Sync, State: Sync, Value: Sync,

§

impl<'map, Key, Value, State> Unpin for Entry<'map, Key, Value, State>
where Key: Unpin,

§

impl<'map, Key, Value, State = RandomState> !UnwindSafe for Entry<'map, Key, Value, State>

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