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<P, T> OccupiedEntry<'_, P, T>
impl<P, T> OccupiedEntry<'_, P, T>
Sourcepub fn key(&self) -> &P
pub fn key(&self) -> &P
Gets a reference to the key in the entry. This is the key that is currently stored, and not the key that was used in the insert.
use prefix_trie::map::Entry;
let mut pm: PrefixMap<ipnet::Ipv4Net, _> = PrefixMap::new();
pm.insert("192.168.1.0/24".parse()?, 1);
match pm.entry("192.168.1.1/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<ipnet::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.
This call will not modify the prefix stored in the tree. In case the prefix used to create
the entry is different from the stored one (has additional information in the host part),
and you wish that prefix to be overwritten, use insert.
use prefix_trie::map::Entry;
let mut pm: PrefixMap<ipnet::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(self, value: T) -> T
pub fn insert(self, value: T) -> T
Insert a new value into the entry, returning the old value. This operation will also replace the prefix with the provided one.
use prefix_trie::map::Entry;
let mut pm: PrefixMap<ipnet::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. The tree will not be modified (the same effect as
PrefixMap::remove_keep_tree).
use prefix_trie::map::Entry;
let mut pm: PrefixMap<ipnet::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);