Struct VacantEntry

pub struct VacantEntry<'a, T, A = Global>
where
    A: Allocator, { /* private fields */ }

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

Examples

# #[cfg(feature = "nightly")]
# fn test() {
use hashbrown::hash_table::{Entry, VacantEntry};
use hashbrown::{HashTable, DefaultHashBuilder};
use std::hash::BuildHasher;

let mut table: HashTable<&str> = HashTable::new();
let hasher = DefaultHashBuilder::default();
let hasher = |val: &_| hasher.hash_one(val);

let entry_v: VacantEntry<_, _> = match table.entry(hasher(&"a"), |&x| x == "a", hasher) {
    Entry::Vacant(view) => view,
    Entry::Occupied(_) => unreachable!(),
};
entry_v.insert("a");
assert!(table.find(hasher(&"a"), |&x| x == "a").is_some() && table.len() == 1);

// Nonexistent key (insert)
match table.entry(hasher(&"b"), |&x| x == "b", hasher) {
    Entry::Vacant(view) => {
        view.insert("b");
    }
    Entry::Occupied(_) => unreachable!(),
}
assert!(table.find(hasher(&"b"), |&x| x == "b").is_some() && table.len() == 2);
# }
# fn main() {
#     #[cfg(feature = "nightly")]
#     test()
# }

Implementations

impl<'a, T, A> VacantEntry<'a, T, A> where A: Allocator,

fn insert(self, value: T) -> OccupiedEntry<'a, T, A>

Inserts a new element into the table with the hash that was used to obtain the VacantEntry.

An OccupiedEntry is returned for the newly inserted element.

Examples

# #[cfg(feature = "nightly")]
# fn test() {
use hashbrown::hash_table::Entry;
use hashbrown::{HashTable, DefaultHashBuilder};
use std::hash::BuildHasher;

let mut table: HashTable<&str> = HashTable::new();
let hasher = DefaultHashBuilder::default();
let hasher = |val: &_| hasher.hash_one(val);

if let Entry::Vacant(o) = table.entry(hasher(&"poneyland"), |&x| x == "poneyland", hasher) {
    o.insert("poneyland");
}
assert_eq!(
    table.find(hasher(&"poneyland"), |&x| x == "poneyland"),
    Some(&"poneyland")
);
# }
# fn main() {
#     #[cfg(feature = "nightly")]
#     test()
# }
fn into_table(self) -> &'a mut HashTable<T, A>

Converts the VacantEntry into a mutable reference to the underlying table.

Trait Implementations

impl<T: Debug, A: Allocator> Debug for VacantEntry<'_, T, A>

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

Auto Trait Implementations

impl<'a, T, A = Global> !UnwindSafe for VacantEntry<'a, T, A>

impl<'a, T, A> Freeze for VacantEntry<'a, T, A> where &'a mut HashTable<T, A>: Freeze,

impl<'a, T, A> RefUnwindSafe for VacantEntry<'a, T, A> where &'a mut HashTable<T, A>: RefUnwindSafe,

impl<'a, T, A> Send for VacantEntry<'a, T, A> where &'a mut HashTable<T, A>: Send,

impl<'a, T, A> Sync for VacantEntry<'a, T, A> where &'a mut HashTable<T, A>: Sync,

impl<'a, T, A> Unpin for VacantEntry<'a, T, A> where &'a mut HashTable<T, A>: Unpin,

impl<'a, T, A> UnsafeUnpin for VacantEntry<'a, T, A> where &'a mut HashTable<T, A>: UnsafeUnpin,

Blanket Implementations

impl<T> Any for VacantEntry<'a, T, A> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for VacantEntry<'a, T, A> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for VacantEntry<'a, T, A> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> From<T> for VacantEntry<'a, T, A>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into<U> for VacantEntry<'a, T, A> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for VacantEntry<'a, T, A> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for VacantEntry<'a, T, A> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>