Struct prefix_trie::map::OccupiedEntry
source · pub struct OccupiedEntry<'a, P, T> { /* private fields */ }Expand description
A mutable view into an occupied entry. An occupied entry represents a node that is already present on the tree.
Implementations§
source§impl<'a, P, T> OccupiedEntry<'a, P, T>
impl<'a, P, T> OccupiedEntry<'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<Ipv4Net, _> = PrefixMap::new();
pm.insert("192.168.1.0/24".parse()?, 1);
match pm.entry("192.168.1.0/24".parse()?) {
Entry::Occupied(e) => assert_eq!(e.key(), &"192.168.1.0/24".parse()?),
Entry::Vacant(_) => unreachable!(),
}sourcepub fn get(&self) -> &T
pub fn get(&self) -> &T
Gets a reference to the value in the entry.
use prefix_trie::map::Entry;
let mut pm: PrefixMap<Ipv4Net, _> = PrefixMap::new();
pm.insert("192.168.1.0/24".parse()?, 1);
match pm.entry("192.168.1.0/24".parse()?) {
Entry::Occupied(e) => assert_eq!(e.get(), &1),
Entry::Vacant(_) => unreachable!(),
}sourcepub fn get_mut(&mut self) -> &mut T
pub fn get_mut(&mut self) -> &mut T
Gets a mutable reference to the value in the entry.
use prefix_trie::map::Entry;
let mut pm: PrefixMap<Ipv4Net, _> = PrefixMap::new();
pm.insert("192.168.1.0/24".parse()?, 1);
match pm.entry("192.168.1.0/24".parse()?) {
Entry::Occupied(mut e) => *e.get_mut() += 1,
Entry::Vacant(_) => unreachable!(),
}
assert_eq!(pm.get(&"192.168.1.0/24".parse()?), Some(&2));sourcepub fn insert(&mut self, value: T) -> T
pub fn insert(&mut self, value: T) -> T
Insert a new value into the entry, returning the old value.
use prefix_trie::map::Entry;
let mut pm: PrefixMap<Ipv4Net, _> = PrefixMap::new();
pm.insert("192.168.1.0/24".parse()?, 1);
match pm.entry("192.168.1.0/24".parse()?) {
Entry::Occupied(mut e) => assert_eq!(e.insert(10), 1),
Entry::Vacant(_) => unreachable!(),
}
assert_eq!(pm.get(&"192.168.1.0/24".parse()?), Some(&10));sourcepub fn remove(&mut self) -> T
pub fn remove(&mut self) -> T
Remove the current value and return it.
use prefix_trie::map::Entry;
let mut pm: PrefixMap<Ipv4Net, i32> = PrefixMap::new();
pm.insert("192.168.1.0/24".parse()?, 1);
match pm.entry("192.168.1.0/24".parse()?) {
Entry::Occupied(mut e) => assert_eq!(e.remove(), 1),
Entry::Vacant(_) => unreachable!(),
}
assert_eq!(pm.get(&"192.168.1.0/24".parse()?), None);