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

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"),
    }
}

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

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

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

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

Formats the value using the given formatter. Read more

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.