pub struct OccupiedEntry<'a, K, V> { /* private fields */ }
Expand description

View into an occupied entry in a LookupMap. This is part of the Entry enum.

Implementations

Gets a reference to the key in the entry.

source

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

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

Examples
use near_sdk::store::LookupMap;
use near_sdk::store::lookup_map::Entry;

let mut map: LookupMap<String, u32> = LookupMap::new(b"m");
map.entry("poneyland".to_string()).or_insert(12);

if let Entry::Occupied(o) = map.entry("poneyland".to_string()) {
    // We delete the entry from the map.
    o.remove_entry();
}

assert_eq!(map.contains_key("poneyland"), false);

Gets a reference to the value in the entry.

Examples
use near_sdk::store::LookupMap;
use near_sdk::store::lookup_map::Entry;

let mut map: LookupMap<String, u32> = LookupMap::new(b"m");
map.entry("poneyland".to_string()).or_insert(12);

if let Entry::Occupied(o) = map.entry("poneyland".to_string()) {
    assert_eq!(o.get(), &12);
}

Gets a mutable reference to the value in the entry.

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

Examples
use near_sdk::store::LookupMap;
use near_sdk::store::lookup_map::Entry;

let mut map: LookupMap<String, u32> = LookupMap::new(b"m");
map.entry("poneyland".to_string()).or_insert(12);

assert_eq!(map["poneyland"], 12);
if let Entry::Occupied(mut o) = map.entry("poneyland".to_string()) {
    *o.get_mut() += 10;
    assert_eq!(*o.get(), 22);

    // We can use the same Entry multiple times.
    *o.get_mut() += 2;
}

assert_eq!(map["poneyland"], 24);

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 near_sdk::store::LookupMap;
use near_sdk::store::lookup_map::Entry;

let mut map: LookupMap<String, u32> = LookupMap::new(b"m");
map.entry("poneyland".to_string()).or_insert(12);

assert_eq!(map["poneyland"], 12);
if let Entry::Occupied(o) = map.entry("poneyland".to_string()) {
    *o.into_mut() += 10;
}

assert_eq!(map["poneyland"], 22);

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

Examples
use near_sdk::store::LookupMap;
use near_sdk::store::lookup_map::Entry;

let mut map: LookupMap<String, u32> = LookupMap::new(b"m");
map.entry("poneyland".to_string()).or_insert(12);

if let Entry::Occupied(mut o) = map.entry("poneyland".to_string()) {
    assert_eq!(o.insert(15), 12);
}

assert_eq!(map["poneyland"], 15);

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

Examples
use near_sdk::store::LookupMap;
use near_sdk::store::lookup_map::Entry;

let mut map: LookupMap<String, u32> = LookupMap::new(b"m");
map.entry("poneyland".to_string()).or_insert(12);

if let Entry::Occupied(o) = map.entry("poneyland".to_string()) {
    assert_eq!(o.remove(), 12);
}

assert_eq!(map.contains_key("poneyland"), false);

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.