Skip to main content

OccupiedEntry

Enum OccupiedEntry 

Source
pub enum OccupiedEntry<'a, P: JointPrefix, T> {
    P1(OccupiedEntry<'a, P::P1, T>),
    P2(OccupiedEntry<'a, P::P2, T>),
}
Expand description

A mutable view into an occupied entry. An occupied entry represents a node that is already present on the tree.

Variants§

§

P1(OccupiedEntry<'a, P::P1, T>)

Occupied entry for the first prefix variant

§

P2(OccupiedEntry<'a, P::P2, T>)

Occupied entry for the second prefix variant

Implementations§

Source§

impl<P: JointPrefix, T> OccupiedEntry<'_, P, T>

Source

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.

Source

pub fn get(&self) -> &T

Gets a reference to the value in the entry.

Source

pub fn get_mut(&mut self) -> &mut T

Gets a mutable reference to the value in the entry.

Prefixes are not stored verbatim. They are reconstructed from the trie position, so host bits masked out by the prefix length are not preserved.

use prefix_trie::joint::map::Entry;
let mut pm: JointPrefixMap<ipnet::IpNet, _> = JointPrefixMap::new();
pm.insert("192.168.1.1/24".parse()?, 1);
if let Entry::Occupied(mut e) = pm.entry("192.168.1.0/24".parse()?) {
    *e.get_mut() += 1;
}
assert_eq!(
    pm.get_key_value(&"192.168.1.0/24".parse()?),
    Some(("192.168.1.0/24".parse()?, &2))
);
Source

pub fn insert(self, value: T) -> T

Insert a new value into the entry, returning the old value.

use prefix_trie::joint::map::Entry;
let mut pm: JointPrefixMap<ipnet::IpNet, _> = JointPrefixMap::new();
pm.insert("192.168.1.1/24".parse()?, 1);
if let Entry::Occupied(mut e) = pm.entry("192.168.1.0/24".parse()?) {
    e.insert(2);
}
assert_eq!(
    pm.get_key_value(&"192.168.1.0/24".parse()?),
    Some(("192.168.1.0/24".parse()?, &2))
);
Source

pub fn remove(self) -> T

Remove the current value and return it. Empty trie nodes may be left in place (the same effect as JointPrefixMap::remove_keep_tree).

Auto Trait Implementations§

§

impl<'a, P, T> Freeze for OccupiedEntry<'a, P, T>
where <P as JointPrefix>::P1: Freeze, <P as JointPrefix>::P2: Freeze,

§

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

§

impl<'a, P, T> Send for OccupiedEntry<'a, P, T>
where <P as JointPrefix>::P1: Send, <P as JointPrefix>::P2: Send, T: Send,

§

impl<'a, P, T> Sync for OccupiedEntry<'a, P, T>
where <P as JointPrefix>::P1: Sync, <P as JointPrefix>::P2: Sync, T: Sync,

§

impl<'a, P, T> Unpin for OccupiedEntry<'a, P, T>
where <P as JointPrefix>::P1: Unpin, <P as JointPrefix>::P2: Unpin,

§

impl<'a, P, T> UnsafeUnpin 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

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>,

Source§

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.