VacantEntry

Struct VacantEntry 

Source
pub struct VacantEntry<'a, K1: 'a, K2: 'a, V: 'a> { /* private fields */ }
Expand description

A view into a vacant entry in a DHashMap. It is part of the Entry enum.

Implementations§

Source§

impl<'a, K1: 'a, K2: 'a, V: 'a> VacantEntry<'a, K1, K2, V>

Source

pub fn key1(&self) -> &K1

Gets a reference to the key #1 of type K1 that would be used when inserting a value through the VacantEntry.

§Examples
use double_map::DHashMap;
use double_map::dhash_map::Entry;

let mut map: DHashMap<&str, u32, i32> = DHashMap::new();

if let Ok(entry) = map.entry("poneyland", 0) {
    match entry {
        Entry::Occupied(_) => panic!("Something go wrong!!!"),
        Entry::Vacant(vac_entry) => assert_eq!(vac_entry.key1(), &"poneyland"),
    }
}
Source

pub fn key2(&self) -> &K2

Gets a reference to the key #2 of type K2 that would be used when inserting a value through the VacantEntry.

§Examples
use double_map::DHashMap;
use double_map::dhash_map::Entry;

let mut map: DHashMap<&str, u32, i32> = DHashMap::new();

if let Ok(entry) = map.entry("poneyland", 0) {
    match entry {
        Entry::Occupied(_) => panic!("Something go wrong!!!"),
        Entry::Vacant(vac_entry) => assert_eq!(vac_entry.key2(), &0),
    }
}
Source

pub fn keys(&self) -> (&K1, &K2)

Gets a reference to the keys of type K1 and K2 that would be used when inserting a value through the VacantEntry. Return tuple of type (&'a K1, &'a K2).

§Examples
use double_map::DHashMap;
use double_map::dhash_map::Entry;

let mut map: DHashMap<&str, u32, i32> = DHashMap::new();

if let Ok(entry) = map.entry("poneyland", 0) {
    match entry {
        Entry::Occupied(_) => panic!("Something go wrong!!!"),
        Entry::Vacant(vac_entry) => {
            assert_eq!(vac_entry.keys(), (&"poneyland", &0))
        }
    }
}
Source

pub fn into_keys(self) -> (K1, K2)

Take the ownership of the keys from the entry.

§Examples
use double_map::DHashMap;
use double_map::dhash_map::Entry;

// So lets create some map and also reserve some space for additional elements
let mut map: DHashMap<&str, u32, i32> = DHashMap::with_capacity(3);

let capacity_before_into_keys = map.capacity();
assert!(capacity_before_into_keys >= 3);

if let Ok(entry) = map.entry("poneyland", 0) {
    match entry {
        Entry::Occupied(_) => panic!("Something go wrong!!!"),
        Entry::Vacant(vac_entry) => {
            // We take the keys from the entry.
            let tuple = vac_entry.into_keys();
            assert_eq!(tuple, ("poneyland", 0));
        }
    }
}

if let Ok(entry) = map.entry("bearland", 1) {
    match entry {
        Entry::Occupied(_) => panic!("Something go wrong!!!"),
        Entry::Vacant(vac_entry) => {
            // We take the keys from the entry.
            let tuple = vac_entry.into_keys();
            assert_eq!(tuple, ("bearland", 1));
        }
    }
}

map.entry("some_key", 2);
map.entry("another_key", 3);

// The capacity of our map is not changed
assert_eq!(map.capacity(), capacity_before_into_keys);
Source§

impl<'a, K1: 'a + Clone, K2: 'a + Clone, V: 'a> VacantEntry<'a, K1, K2, V>

Source

pub fn insert(self, value: V) -> &'a mut V

Sets the value of the entry with the VacantEntry’s keys, and returns a mutable reference to it.

§Examples
use double_map::DHashMap;
use double_map::dhash_map::Entry;

// So lets create some map
let mut map: DHashMap<&str, u32, i32> = DHashMap::new();

if let Ok(entry) = map.entry("poneyland", 0) {
    match entry {
        Entry::Occupied(_) => panic!("Something go wrong!!!"),
        Entry::Vacant(vac_entry) => {
            vac_entry.insert(37);
        }
    }
}
assert_eq!(map.get_key1(&"poneyland"), Some(&37));

Trait Implementations§

Source§

impl<'a, K1: Debug + 'a, K2: Debug + 'a, V: Debug + 'a> Debug for VacantEntry<'a, K1, K2, V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, K1, K2, V> Freeze for VacantEntry<'a, K1, K2, V>
where K1: Freeze, K2: Freeze,

§

impl<'a, K1, K2, V> RefUnwindSafe for VacantEntry<'a, K1, K2, V>

§

impl<'a, K1, K2, V> Send for VacantEntry<'a, K1, K2, V>
where K1: Send, K2: Send, V: Send,

§

impl<'a, K1, K2, V> Sync for VacantEntry<'a, K1, K2, V>
where K1: Sync, K2: Sync, V: Sync,

§

impl<'a, K1, K2, V> Unpin for VacantEntry<'a, K1, K2, V>
where K1: Unpin, K2: Unpin,

§

impl<'a, K1, K2, V> !UnwindSafe for VacantEntry<'a, K1, K2, V>

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

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.