pub struct VacantEntry<'a, T, S, A: Allocator + Clone = Global> { /* private fields */ }
Expand description

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

Examples

use hashbrown::hash_set::{Entry, HashSet, VacantEntry};

let mut set = HashSet::<&str>::new();

let entry_v: VacantEntry<_, _> = match set.entry("a") {
    Entry::Vacant(view) => view,
    Entry::Occupied(_) => unreachable!(),
};
entry_v.insert();
assert!(set.contains("a") && set.len() == 1);

// Nonexistent key (insert)
match set.entry("b") {
    Entry::Vacant(view) => view.insert(),
    Entry::Occupied(_) => unreachable!(),
}
assert!(set.contains("b") && set.len() == 2);

Implementations

Gets a reference to the value that would be used when inserting through the VacantEntry.

Examples
use hashbrown::HashSet;

let mut set: HashSet<&str> = HashSet::new();
assert_eq!(set.entry("poneyland").get(), &"poneyland");

Take ownership of the value.

Examples
use hashbrown::hash_set::{Entry, HashSet};

let mut set: HashSet<&str> = HashSet::new();

match set.entry("poneyland") {
    Entry::Occupied(_) => panic!(),
    Entry::Vacant(v) => assert_eq!(v.into_value(), "poneyland"),
}

Sets the value of the entry with the VacantEntry’s value.

Examples
use hashbrown::HashSet;
use hashbrown::hash_set::Entry;

let mut set: HashSet<&str> = HashSet::new();

if let Entry::Vacant(o) = set.entry("poneyland") {
    o.insert();
}
assert!(set.contains("poneyland"));

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.