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>

source

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

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

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

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

pub fn remove(&mut self) -> T

Remove the current value and return it.

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

Auto Trait Implementations§

§

impl<'a, P, T> Freeze for OccupiedEntry<'a, P, T>

§

impl<'a, P, T> RefUnwindSafe for OccupiedEntry<'a, P, T>

§

impl<'a, P, T> Send for OccupiedEntry<'a, P, T>
where P: Send, T: Send,

§

impl<'a, P, T> Sync for OccupiedEntry<'a, P, T>
where P: Sync, T: Sync,

§

impl<'a, P, T> Unpin for OccupiedEntry<'a, P, T>

§

impl<'a, P, T> !UnwindSafe for OccupiedEntry<'a, P, T>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.