pub enum Entry<'a, K1: 'a, K2: 'a, V: 'a> {
    Occupied(OccupiedEntry<'a, K1, K2, V>),
    Vacant(VacantEntry<'a, K1, K2, V>),
}
Expand description

A view into a single entry in a map, which may either be vacant or occupied.

This enum is constructed from the entry method on DHashMap.

Variants

Occupied(OccupiedEntry<'a, K1, K2, V>)

An occupied entry.

Vacant(VacantEntry<'a, K1, K2, V>)

A vacant entry.

Implementations

Ensures a value is in the entry by inserting the default if empty, and returns a mutable reference to the value in the entry.

Examples
use double_map::DHashMap;

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

match map.entry("poneyland", 0) {
    Ok(entry) => {
        entry.or_insert(3);
    }
    Err(_) => unreachable!(),
}
assert_eq!(map.get_key1(&"poneyland"), Some(&3));

map.entry("poneyland", 0).map(|entry| *entry.or_insert(10) *= 2);
assert_eq!(map.get_key1(&"poneyland"), Some(&6));

Ensures a value is in the entry by inserting the result of the default function if empty, and returns a mutable reference to the value in the entry.

Examples
use double_map::DHashMap;

let mut map: DHashMap<&str, u32, String> = DHashMap::new();
let s = "hoho".to_owned();

match map.entry("poneyland", 0) {
    Ok(entry) => {
        entry.or_insert_with(|| s);
    }
    Err(_) => unreachable!(),
}
assert_eq!(map.get_key1("poneyland"), Some(&"hoho".to_owned()));

let k = "another string".to_owned();
map.entry("poneyland", 0).map(|entry| entry.or_insert_with(|| k).push_str("ho"));
assert_eq!(map.get_key1(&"poneyland"), Some(&"hohoho".to_owned()));

Ensures a value is in the entry by inserting, if empty, the result of the default function. This method allows generating key-derived (with using key # 1 K1) value for insertion by providing the default function a reference to the key that was moved during the .entry(key) method call.

The reference to the moved key is provided so that cloning or copying the key is unnecessary, unlike with .or_insert_with(|| ... ).

Examples
use double_map::DHashMap;

let mut map: DHashMap<&str, usize, u64> = DHashMap::new();

 match map.entry("poneyland", 0) {
    Ok(entry) => {
        entry.or_insert_with_key1(|k1| k1.chars().count() as u64);
    },
    Err(_) => unreachable!(),
}
assert_eq!(map.get_key1(&"poneyland"), Some(&9));

map.entry("bearland", 1).map(
    |ent| ent.or_insert_with_key1(|k1| (k1.chars().count() * 2) as u64)
);
assert_eq!(map.get_key1(&"bearland"), Some(&16));

Ensures a value is in the entry by inserting, if empty, the result of the default function. This method allows generating key-derived (with using key # 2 K2) value for insertion by providing the default function a reference to the key that was moved during the .entry(key) method call.

The reference to the moved key is provided so that cloning or copying the key is unnecessary, unlike with .or_insert_with(|| ... ).

Examples
use double_map::DHashMap;

let mut map: DHashMap<&str, usize, u64> = DHashMap::new();

 match map.entry("poneyland", 10) {
    Ok(entry) => {
        entry.or_insert_with_key2(|k2| (k2 + 10) as u64);
    },
    Err(_) => unreachable!(),
}
assert_eq!(map.get_key1(&"poneyland"), Some(&20));

map.entry("bearland", 11).map(
    |ent| ent.or_insert_with_key2(|k1| (k1 * 3) as u64)
);
assert_eq!(map.get_key1(&"bearland"), Some(&33));

Ensures a value is in the entry by inserting, if empty, the result of the default function. This method allows generating key-derived (with using key #1 of type K1 and key # 2 of type K2) values for insertion by providing the default function a reference to the keys that were moved during the .entry(key) method call.

The reference to the moved keys is provided so that cloning or copying the key is unnecessary, unlike with .or_insert_with(|| ... ).

Examples
use double_map::DHashMap;

let mut map: DHashMap<&str, usize, u64> = DHashMap::new();

 match map.entry("poneyland", 10) {
    Ok(entry) => {
        entry.or_insert_with_keys(|k1, k2| (k1.chars().count() + k2) as u64);
    },
    Err(_) => unreachable!(),
}
assert_eq!(map.get_key1(&"poneyland"), Some(&19));

map.entry("bearland", 11).map(
    |ent| ent.or_insert_with_keys(|k1, k2| (k1.chars().count() + k2 * 3) as u64)
);
assert_eq!(map.get_key1(&"bearland"), Some(&41));

Returns a reference to this entry’s first key (key #1).

Examples
use double_map::DHashMap;

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

// It is VacantEntry
match map.entry("poneyland", 0) {
    Ok(entry) => {
        // key equal to provided one
        assert_eq!(entry.key1(), &"poneyland");
        // we insert some value
        entry.or_insert(25);
    },
    Err(_) => unreachable!(),
}
// As we can see, now this element exists
assert_eq!(map.get_key1(&"poneyland"), Some(&25));

// So now it is OccupiedEntry
match map.entry("poneyland", 0) {
    Ok(entry) => {
        // And key equals to provided one too
        assert_eq!(entry.key1(), &"poneyland");
        entry.or_insert(25);
    },
    Err(_) => unreachable!(),
}

Returns a reference to this entry’s second key (key #2).

Examples
use double_map::DHashMap;

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

// It is VacantEntry
match map.entry("poneyland", 10) {
    Ok(entry) => {
        // key equal to provided one
        assert_eq!(entry.key2(), &10);
        // we insert some value
        entry.or_insert(25);
    },
    Err(_) => unreachable!(),
}
// As we can see, now this element exists
assert_eq!(map.get_key2(&10), Some(&25));

// So now it is OccupiedEntry
match map.entry("poneyland", 10) {
    Ok(entry) => {
        // And key equals to provided one too
        assert_eq!(entry.key2(), &10);
        entry.or_insert(25);
    },
    Err(_) => unreachable!(),
}

Returns a reference to this entry’s keys. Return tuple of type (&’a K1, &’a K2).

Examples
use double_map::DHashMap;

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

// It is VacantEntry
match map.entry("poneyland", 10) {
    Ok(entry) => {
        // keys equal to provided one
        assert_eq!(entry.keys(), (&"poneyland", &10));
        // we insert some value
        entry.or_insert(25);
    },
    Err(_) => unreachable!(),
}
// As we can see, now this element exists
assert_eq!(map.get_key1(&"poneyland"), Some(&25));

// So now it is OccupiedEntry
match map.entry("poneyland", 10) {
    Ok(entry) => {
        // And keys equal to provided one too
        assert_eq!(entry.keys(), (&"poneyland", &10));
        entry.or_insert(25);
    },
    Err(_) => unreachable!(),
}

Provides in-place mutable access to an occupied entry before any potential inserts into the map.

Examples
use double_map::DHashMap;

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

map.entry("poneyland", 1).map( |entry|
   entry.and_modify(|value| { *value += 100 })
   .or_insert(42)
);
assert_eq!(map.get_key1(&"poneyland"), Some(&42));

map.entry("poneyland", 1).map( |entry|
   entry.and_modify(|value| { *value += 100 })
   .or_insert(42)
);
assert_eq!(map.get_key1(&"poneyland"), Some(&142));

Ensures a value is in the entry by inserting the default value if empty, and returns a mutable reference to the value in the entry.

Examples
use double_map::DHashMap;

let mut map: DHashMap<&str, usize, Option<u32>> = DHashMap::new();
map.entry("poneyland", 1).map(|entry| entry.or_default());

assert_eq!(map.get_key1(&"poneyland"), Option::<&Option<u32>>::Some(&None));

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.