pub struct VacantEntry<'a, P, T> { /* private fields */ }
Expand description

A mutable view into a missing entry. The information within this structure describes a path towards that missing node, and how to insert it.

Implementations§

source§

impl<'a, P, T> VacantEntry<'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, i32> = PrefixMap::new();
match pm.entry("192.168.1.0/24".parse()?) {
    Entry::Vacant(e) => assert_eq!(e.key(), &"192.168.1.0/24".parse()?),
    Entry::Occupied(_) => unreachable!(),
}
source§

impl<'a, P, T> VacantEntry<'a, P, T>
where P: Prefix,

source

pub fn insert(self, default: T) -> &'a mut T

Get a mutable reference to the value. If the value is yet empty, set it to the given default value.

use prefix_trie::map::Entry;
let mut pm: PrefixMap<ipnet::Ipv4Net, i32> = PrefixMap::new();
match pm.entry("192.168.1.0/24".parse()?) {
    Entry::Vacant(mut e) => assert_eq!(e.insert(10), &10),
    Entry::Occupied(_) => unreachable!(),
}
assert_eq!(pm.get(&"192.168.1.0/24".parse()?), Some(&10));
source

pub fn insert_with<F: FnOnce() -> T>(self, default: F) -> &'a mut T

Get a mutable reference to the value. If the value is yet empty, set it to the return value from the given function.

use prefix_trie::map::Entry;
let mut pm: PrefixMap<ipnet::Ipv4Net, i32> = PrefixMap::new();
match pm.entry("192.168.1.0/24".parse()?) {
    Entry::Vacant(mut e) => assert_eq!(e.insert_with(|| 10), &10),
    Entry::Occupied(_) => unreachable!(),
}
assert_eq!(pm.get(&"192.168.1.0/24".parse()?), Some(&10));
source§

impl<'a, P, T> VacantEntry<'a, P, T>
where P: Prefix, T: Default,

source

pub fn default(self) -> &'a mut T

Get a mutable reference to the value. If the value is yet empty, set it to the default value using Default::default().

use prefix_trie::map::Entry;
let mut pm: PrefixMap<ipnet::Ipv4Net, i32> = PrefixMap::new();
match pm.entry("192.168.1.0/24".parse()?) {
    Entry::Vacant(e) => assert_eq!(e.default(), &0),
    Entry::Occupied(_) => unreachable!(),
}
assert_eq!(pm.get(&"192.168.1.0/24".parse()?), Some(&0));

Auto Trait Implementations§

§

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

§

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

§

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

§

impl<'a, P, T> Unpin for VacantEntry<'a, P, T>
where P: Unpin,

§

impl<'a, P, T> !UnwindSafe for VacantEntry<'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.