pub struct VacantEntryRef<'a, 'b, K, Q, V, S>where
Q: ?Sized,{ /* private fields */ }
Expand description
A view into a vacant entry in a StableMap
.
It is part of the EntryRef
enum.
§Examples
use stable_map::{EntryRef, StableMap, VacantEntryRef};
let mut map = StableMap::<String, i32>::new();
let entry_v: VacantEntryRef<_, _, _, _> = match map.entry_ref("a") {
EntryRef::Vacant(view) => view,
EntryRef::Occupied(_) => unreachable!(),
};
entry_v.insert(10);
assert!(map["a"] == 10 && map.len() == 1);
// Nonexistent key (insert and update)
match map.entry_ref("b") {
EntryRef::Occupied(_) => unreachable!(),
EntryRef::Vacant(view) => {
let value = view.insert(2);
assert_eq!(*value, 2);
*value = 20;
}
}
assert!(map["b"] == 20 && map.len() == 2);
Implementations§
Source§impl<'a, 'b, K, Q, V, S> VacantEntryRef<'a, 'b, K, Q, V, S>where
Q: ?Sized,
impl<'a, 'b, K, Q, V, S> VacantEntryRef<'a, 'b, K, Q, V, S>where
Q: ?Sized,
Sourcepub fn insert(self, value: V) -> &'a mut V
pub fn insert(self, value: V) -> &'a mut V
Sets the value of the entry, and returns an OccupiedEntry
.
§Examples
use stable_map::StableMap;
let mut map: StableMap<String, u32> = StableMap::new();
let entry = map.entry_ref("horseyland").insert(37);
assert_eq!(entry.key(), "horseyland");
Sourcepub fn insert_entry(self, value: V) -> OccupiedEntry<'a, K, V, S>
pub fn insert_entry(self, value: V) -> OccupiedEntry<'a, K, V, S>
Sets the value of the entry with the VacantEntryRef
’s key,
and returns an OccupiedEntry
.
§Examples
use stable_map::{EntryRef, StableMap};
let mut map: StableMap<&str, u32> = StableMap::new();
if let EntryRef::Vacant(v) = map.entry_ref("poneyland") {
let o = v.insert_entry(37);
assert_eq!(o.get(), &37);
}
Sourcepub fn key(&self) -> &'b Q
pub fn key(&self) -> &'b Q
Gets a reference to the key that would be used when inserting a value
through the VacantEntryRef
.
§Examples
use stable_map::StableMap;
let mut map: StableMap<String, u32> = StableMap::new();
let key: &str = "poneyland";
assert_eq!(map.entry_ref(key).key(), "poneyland");
Trait Implementations§
Source§impl<K, Q, V, S> Debug for VacantEntryRef<'_, '_, K, Q, V, S>
impl<K, Q, V, S> Debug for VacantEntryRef<'_, '_, K, Q, V, S>
impl<K, Q, V, S> Send for VacantEntryRef<'_, '_, K, Q, V, S>
impl<K, Q, V, S> Sync for VacantEntryRef<'_, '_, K, Q, V, S>
Auto Trait Implementations§
impl<'a, 'b, K, Q, V, S> Freeze for VacantEntryRef<'a, 'b, K, Q, V, S>where
Q: ?Sized,
impl<'a, 'b, K, Q, V, S> RefUnwindSafe for VacantEntryRef<'a, 'b, K, Q, V, S>
impl<'a, 'b, K, Q, V, S> Unpin for VacantEntryRef<'a, 'b, K, Q, V, S>where
Q: ?Sized,
impl<'a, 'b, K, Q, V, S> !UnwindSafe for VacantEntryRef<'a, 'b, K, Q, V, S>
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