Struct near_sdk::store::unordered_map::VacantEntry
source · pub struct VacantEntry<'a, K, V>where
K: BorshSerialize,{ /* private fields */ }
Expand description
View into a vacant entry in a UnorderedMap
.
This is part of the Entry
enum.
Implementations§
source§impl<'a, K, V> VacantEntry<'a, K, V>where
K: BorshSerialize,
impl<'a, K, V> VacantEntry<'a, K, V>where
K: BorshSerialize,
sourcepub fn key(&self) -> &K
pub fn key(&self) -> &K
Gets a reference to the key that would be used when inserting a value
through the VacantEntry
.
sourcepub fn into_key(self) -> K
pub fn into_key(self) -> K
Take ownership of the key.
§Examples
use near_sdk::store::UnorderedMap;
use near_sdk::store::unordered_map::Entry;
let mut map: UnorderedMap<String, u32> = UnorderedMap::new(b"m");
if let Entry::Vacant(v) = map.entry("poneyland".to_string()) {
v.into_key();
}
sourcepub fn insert(self, value: V) -> &'a mut Vwhere
K: BorshDeserialize + Clone,
pub fn insert(self, value: V) -> &'a mut Vwhere
K: BorshDeserialize + Clone,
Sets the value of the entry with the VacantEntry
’s key,
and returns a mutable reference to it.
§Examples
use near_sdk::store::UnorderedMap;
use near_sdk::store::unordered_map::Entry;
let mut map: UnorderedMap<String, u32> = UnorderedMap::new(b"m");
if let Entry::Vacant(o) = map.entry("poneyland".to_string()) {
o.insert(37);
}
assert_eq!(map["poneyland"], 37);
Auto Trait Implementations§
impl<'a, K, V> Freeze for VacantEntry<'a, K, V>where
K: Freeze,
impl<'a, K, V> !RefUnwindSafe for VacantEntry<'a, K, V>
impl<'a, K, V> Send for VacantEntry<'a, K, V>
impl<'a, K, V> !Sync for VacantEntry<'a, K, V>
impl<'a, K, V> Unpin for VacantEntry<'a, K, V>where
K: Unpin,
impl<'a, K, V> !UnwindSafe for VacantEntry<'a, K, V>
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