pub struct OccupiedEntry<'a, K, V, S: Storage<ListMapLayout<K, V>>, I: Capacity> { /* private fields */ }Implementations§
Source§impl<'a, K, V, S: Storage<ListMapLayout<K, V>>, I: Capacity> OccupiedEntry<'a, K, V, S, I>
impl<'a, K, V, S: Storage<ListMapLayout<K, V>>, I: Capacity> OccupiedEntry<'a, K, V, S, I>
Sourcepub fn remove_entry(self) -> (K, V)
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);Sourcepub fn get(&self) -> &V
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);
}Sourcepub fn get_mut(&mut self) -> &mut V
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));Sourcepub fn into_mut(self) -> &'a mut V
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));Sourcepub fn insert(&mut self, value: V) -> V
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));Sourcepub fn remove(self) -> V
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);Sourcepub fn replace_entry(self, value: V) -> (K, V)
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));Sourcepub fn replace_key(self) -> K
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.