OccupiedEntry

Struct OccupiedEntry 

Source
pub struct OccupiedEntry<'a, K, V, S: Storage<ListMapLayout<K, V>>, I: Capacity> { /* private fields */ }
Expand description

A view into an occupied entry in a ListMap. It is part of the Entry enum.

Implementations§

Source§

impl<'a, K, V, S: Storage<ListMapLayout<K, V>>, I: Capacity> OccupiedEntry<'a, K, V, S, I>

Source

pub fn key(&self) -> &K

Gets a reference to the key used to create the entry.

Source

pub fn remove_entry(self) -> (K, V)

Take the ownership of the key and value from the map.

§Examples
use coca::collections::InlineListMap;
use coca::collections::list_map::Entry;
 
let mut map = InlineListMap::<&'static str, u32, 4>::new();
 
map.entry("foobar").or_insert(12);
assert_eq!(map.get("foobar"), Some(&12));
 
if let Entry::Occupied(o) = map.entry("foobar") {
    o.remove_entry();
}
 
assert_eq!(map.contains_key("foobar"), false);
Source

pub fn get(&self) -> &V

Gets a reference to the value in the entry.

§Examples
use coca::collections::InlineListMap;
use coca::collections::list_map::Entry;
 
let mut map = InlineListMap::<&'static str, u32, 4>::new();
 
map.entry("foobar").or_insert(12);
assert_eq!(map.get("foobar"), Some(&12));
 
if let Entry::Occupied(o) = map.entry("foobar") {
    assert_eq!(o.get(), &12);
}
Source

pub fn get_mut(&mut self) -> &mut V

Gets a mutable reference to the value in the entry.

If you need a reference to the value which may outlive the Entry, see into_mut.

§Examples
use coca::collections::InlineListMap;
use coca::collections::list_map::Entry;
 
let mut map = InlineListMap::<&'static str, u32, 4>::new();
 
map.entry("foobar").or_insert(12);
assert_eq!(map.get("foobar"), Some(&12));
 
if let Entry::Occupied(mut o) = map.entry("foobar") {
    *o.get_mut() += 10;
    assert_eq!(*o.get(), 22);
 
    // You can use the same Entry multiple times:
    *o.get_mut() += 2;
}
 
assert_eq!(map.get("foobar"), Some(&24));
Source

pub fn into_mut(self) -> &'a mut V

Converts the OccupiedEntry into a mutable reference to the value in the entry with a lifetime bound to the map itself.

If you need multiple references to the OccupiedEntry, see get_mut.

§Examples
use coca::collections::InlineListMap;
use coca::collections::list_map::Entry;
 
let mut map = InlineListMap::<&'static str, u32, 4>::new();
 
map.entry("foobar").or_insert(12);
assert_eq!(map.get("foobar"), Some(&12));
 
if let Entry::Occupied(o) = map.entry("foobar") {
    *o.into_mut() += 10;
}
 
assert_eq!(map.get("foobar"), Some(&22));
Source

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

Sets the value of the entry, and returns the entry’s old value.

§Examples
use coca::collections::InlineListMap;
use coca::collections::list_map::Entry;
 
let mut map = InlineListMap::<&'static str, u32, 4>::new();
 
map.entry("foobar").or_insert(12);
assert_eq!(map.get("foobar"), Some(&12));
 
if let Entry::Occupied(mut o) = map.entry("foobar") {
    assert_eq!(o.insert(15), 12);
}
 
assert_eq!(map.get("foobar"), Some(&15));
Source

pub fn remove(self) -> V

Takes the value out of the entry, and returns it.

§Examples
use coca::collections::InlineListMap;
use coca::collections::list_map::Entry;
 
let mut map = InlineListMap::<&'static str, u32, 4>::new();
 
map.entry("foobar").or_insert(12);
assert_eq!(map.get("foobar"), Some(&12));
 
if let Entry::Occupied(o) = map.entry("foobar") {
    assert_eq!(o.remove(), 12);
}
 
assert_eq!(map.contains_key("foobar"), false);
Source

pub fn replace_entry(self, value: V) -> (K, V)

Replaces the entry, returning the old key-value pair. The new key in the map will be the key used to create the entry.

§Examples
use coca::collections::InlineListMap;
use coca::collections::list_map::Entry;
 
let mut map = InlineListMap::<&'static str, u32, 4>::new();
map.insert("foobar", 15);
 
if let Entry::Occupied(entry) = map.entry("foobar") {
    let (old_key, old_value) = entry.replace_entry(16);
     
    assert_eq!(old_key, "foobar");
    assert_eq!(old_value, 15);
}
 
assert_eq!(map.get("foobar"), Some(&16));
Source

pub fn replace_key(self) -> K

Replaces the key in the map with the one used to create the entry.

This matters for key types that can be == without being identical.

Trait Implementations§

Source§

impl<K: Debug, V: Debug, S: Storage<ListMapLayout<K, V>>, I: Capacity> Debug for OccupiedEntry<'_, K, V, S, I>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, K, V, S, I> Freeze for OccupiedEntry<'a, K, V, S, I>
where K: Freeze,

§

impl<'a, K, V, S, I> RefUnwindSafe for OccupiedEntry<'a, K, V, S, I>

§

impl<'a, K, V, S, I> Send for OccupiedEntry<'a, K, V, S, I>
where K: Send, S: Send, I: Send, V: Send,

§

impl<'a, K, V, S, I> Sync for OccupiedEntry<'a, K, V, S, I>
where K: Sync, S: Sync, I: Sync, V: Sync,

§

impl<'a, K, V, S, I> Unpin for OccupiedEntry<'a, K, V, S, I>
where K: Unpin,

§

impl<'a, K, V, S, I> !UnwindSafe for OccupiedEntry<'a, K, V, S, I>

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

Source§

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

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.