pub enum Entry<'a, K, V, C = Slab<Node<K, V>>> {
Vacant(VacantEntry<'a, K, V, C>),
Occupied(OccupiedEntry<'a, K, V, C>),
}Expand description
Variants§
Vacant(VacantEntry<'a, K, V, C>)
Occupied(OccupiedEntry<'a, K, V, C>)
Implementations§
Source§impl<'a, K, V, C> Entry<'a, K, V, C>
impl<'a, K, V, C> Entry<'a, K, V, C>
Sourcepub fn or_insert(self, default: V) -> &'a mut V
pub fn or_insert(self, default: V) -> &'a mut V
Ensures a value is in the entry by inserting the default if empty, and returns a mutable reference to the value in the entry.
§Examples
use btree_slab::BTreeMap;
let mut map: BTreeMap<&str, usize> = BTreeMap::new();
map.entry("poneyland").or_insert(12);
assert_eq!(map["poneyland"], 12);Sourcepub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V
pub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V
Ensures a value is in the entry by inserting the result of the default function if empty, and returns a mutable reference to the value in the entry.
§Examples
use btree_slab::BTreeMap;
let mut map: BTreeMap<&str, String> = BTreeMap::new();
let s = "hoho".to_string();
map.entry("poneyland").or_insert_with(|| s);
assert_eq!(map["poneyland"], "hoho".to_string());Sourcepub fn or_insert_with_key<F: FnOnce(&K) -> V>(self, default: F) -> &'a mut V
pub fn or_insert_with_key<F: FnOnce(&K) -> V>(self, default: F) -> &'a mut V
Ensures a value is in the entry by inserting, if empty, the result of the default function, which takes the key as its argument, and returns a mutable reference to the value in the entry.
§Examples
use btree_slab::BTreeMap;
let mut map: BTreeMap<&str, usize> = BTreeMap::new();
map.entry("poneyland").or_insert_with_key(|key| key.chars().count());
assert_eq!(map["poneyland"], 9);Sourcepub fn and_modify<F>(self, f: F) -> Self
pub fn and_modify<F>(self, f: F) -> Self
Provides in-place mutable access to an occupied entry before any potential inserts into the map.
§Examples
use btree_slab::BTreeMap;
let mut map: BTreeMap<&str, usize> = BTreeMap::new();
map.entry("poneyland")
.and_modify(|e| { *e += 1 })
.or_insert(42);
assert_eq!(map["poneyland"], 42);
map.entry("poneyland")
.and_modify(|e| { *e += 1 })
.or_insert(42);
assert_eq!(map["poneyland"], 43);Sourcepub fn or_default(self) -> &'a mut Vwhere
V: Default,
pub fn or_default(self) -> &'a mut Vwhere
V: Default,
Ensures a value is in the entry by inserting the default value if empty, and returns a mutable reference to the value in the entry.
§Examples
use btree_slab::BTreeMap;
let mut map: BTreeMap<&str, Option<usize>> = BTreeMap::new();
map.entry("poneyland").or_default();
assert_eq!(map["poneyland"], None);Trait Implementations§
Auto Trait Implementations§
impl<'a, K, V, C> Freeze for Entry<'a, K, V, C>where
K: Freeze,
impl<'a, K, V, C> RefUnwindSafe for Entry<'a, K, V, C>
impl<'a, K, V, C> Send for Entry<'a, K, V, C>
impl<'a, K, V, C> Sync for Entry<'a, K, V, C>
impl<'a, K, V, C> Unpin for Entry<'a, K, V, C>where
K: Unpin,
impl<'a, K, V, C = Slab<Node<K, V>>> !UnwindSafe for Entry<'a, K, V, C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more