Struct VacantEntryRef

Source
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,

Source

pub fn insert(self, value: V) -> &'a mut V
where K: Hash + From<&'b Q>, S: BuildHasher,

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");
Source

pub fn insert_entry(self, value: V) -> OccupiedEntry<'a, K, V, S>
where K: Hash + From<&'b Q>, S: BuildHasher,

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);
}
Source

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>
where Q: Debug, V: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K, Q, V, S> Send for VacantEntryRef<'_, '_, K, Q, V, S>
where Q: Send, K: Send, V: Send, S: Send,

Source§

impl<K, Q, V, S> Sync for VacantEntryRef<'_, '_, K, Q, V, S>
where Q: Sync, K: Sync, V: Sync, S: Sync,

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.