Trait fixed_map::map::VacantEntry
source · pub trait VacantEntry<'a, K, V> {
// Required methods
fn key(&self) -> K;
fn insert(self, value: V) -> &'a mut V;
}Required Methods§
sourcefn key(&self) -> K
fn key(&self) -> K
Gets a copy of the key that would be used
when inserting a value through the VacantEntry.
Examples
use fixed_map::{Key, Map};
use fixed_map::map::{Entry, VacantEntry};
#[derive(Clone, Copy, Key, Debug, PartialEq)]
enum Key {
First,
Second,
}
let mut map: Map<Key, i32> = Map::new();
let vacant = match map.entry(Key::First) {
Entry::Vacant(entry) => entry,
_ => unreachable!(),
};
assert_eq!(vacant.key(), Key::First);Using a composite key:
use fixed_map::{Key, Map};
use fixed_map::map::{Entry, VacantEntry};
#[derive(Clone, Copy, Key, Debug, PartialEq)]
enum Key {
First(bool),
Second,
}
let mut map: Map<Key, i32> = Map::new();
let vacant = match map.entry(Key::First(false)) {
Entry::Vacant(entry) => entry,
_ => unreachable!(),
};
assert_eq!(vacant.key(), Key::First(false));sourcefn insert(self, value: V) -> &'a mut V
fn insert(self, value: V) -> &'a mut V
Sets the value of the entry with the VacantEntry’s key,
and returns a mutable reference to it.
Examples
use fixed_map::{Key, Map};
use fixed_map::map::{Entry, VacantEntry};
#[derive(Clone, Copy, Key)]
enum Key {
First,
Second,
}
let mut map: Map<Key, i32> = Map::new();
if let Entry::Vacant(vacant) = map.entry(Key::First) {
assert_eq!(vacant.insert(37), &37);
}
assert_eq!(map.get(Key::First), Some(&37));Using a composite key:
use fixed_map::{Key, Map};
use fixed_map::map::{Entry, VacantEntry};
#[derive(Clone, Copy, Key)]
enum Key {
First(bool),
Second,
}
let mut map: Map<Key, i32> = Map::new();
if let Entry::Vacant(vacant) = map.entry(Key::First(false)) {
assert_eq!(vacant.insert(37), &37);
}
assert_eq!(map.get(Key::First(false)), Some(&37));