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§

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!(),
}

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!(),
}

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

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

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

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.