Struct prefix_trie::map::VacantEntry
source · pub struct VacantEntry<'a, P, T> { /* private fields */ }Expand description
A mutable view into a missing entry. The information within this structure describes a path towards that missing node, and how to insert it.
Implementations§
source§impl<'a, P, T> VacantEntry<'a, P, T>
impl<'a, P, T> VacantEntry<'a, P, T>
sourcepub fn key(&self) -> &P
pub fn key(&self) -> &P
Gets a reference to the key in the entry.
use prefix_trie::map::Entry;
let mut pm: PrefixMap<ipnet::Ipv4Net, i32> = PrefixMap::new();
match pm.entry("192.168.1.0/24".parse()?) {
Entry::Vacant(e) => assert_eq!(e.key(), &"192.168.1.0/24".parse()?),
Entry::Occupied(_) => unreachable!(),
}source§impl<'a, P, T> VacantEntry<'a, P, T>where
P: Prefix,
impl<'a, P, T> VacantEntry<'a, P, T>where
P: Prefix,
sourcepub fn insert(self, default: T) -> &'a mut T
pub fn insert(self, default: T) -> &'a mut T
Get a mutable reference to the value. If the value is yet empty, set it to the given default value.
use prefix_trie::map::Entry;
let mut pm: PrefixMap<ipnet::Ipv4Net, i32> = PrefixMap::new();
match pm.entry("192.168.1.0/24".parse()?) {
Entry::Vacant(mut e) => assert_eq!(e.insert(10), &10),
Entry::Occupied(_) => unreachable!(),
}
assert_eq!(pm.get(&"192.168.1.0/24".parse()?), Some(&10));sourcepub fn insert_with<F: FnOnce() -> T>(self, default: F) -> &'a mut T
pub fn insert_with<F: FnOnce() -> T>(self, default: F) -> &'a mut T
Get a mutable reference to the value. If the value is yet empty, set it to the return value from the given function.
use prefix_trie::map::Entry;
let mut pm: PrefixMap<ipnet::Ipv4Net, i32> = PrefixMap::new();
match pm.entry("192.168.1.0/24".parse()?) {
Entry::Vacant(mut e) => assert_eq!(e.insert_with(|| 10), &10),
Entry::Occupied(_) => unreachable!(),
}
assert_eq!(pm.get(&"192.168.1.0/24".parse()?), Some(&10));source§impl<'a, P, T> VacantEntry<'a, P, T>
impl<'a, P, T> VacantEntry<'a, P, T>
sourcepub fn default(self) -> &'a mut T
pub fn default(self) -> &'a mut T
Get a mutable reference to the value. If the value is yet empty, set it to the default value
using Default::default().
use prefix_trie::map::Entry;
let mut pm: PrefixMap<ipnet::Ipv4Net, i32> = PrefixMap::new();
match pm.entry("192.168.1.0/24".parse()?) {
Entry::Vacant(e) => assert_eq!(e.default(), &0),
Entry::Occupied(_) => unreachable!(),
}
assert_eq!(pm.get(&"192.168.1.0/24".parse()?), Some(&0));Auto Trait Implementations§
impl<'a, P, T> RefUnwindSafe for VacantEntry<'a, P, T>where
P: RefUnwindSafe,
T: RefUnwindSafe,
impl<'a, P, T> Send for VacantEntry<'a, P, T>
impl<'a, P, T> Sync for VacantEntry<'a, P, T>
impl<'a, P, T> Unpin for VacantEntry<'a, P, T>where
P: Unpin,
impl<'a, P, T> !UnwindSafe for VacantEntry<'a, P, T>
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