Struct std::collections::hash_map::VacantEntry
pub struct VacantEntry<'a, K: 'a, V: 'a> { /* fields omitted */ }
A view into a vacant entry in a HashMap
. It is part of the Entry
enum.
Implementations
impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V>
[src]1.10.0
pub fn key(&self) -> &K
Gets a reference to the key that would be used when inserting a value through the VacantEntry
.
Examples
use std::collections::HashMap; let mut map: HashMap<&str, u32> = HashMap::new(); assert_eq!(map.entry("poneyland").key(), &"poneyland");
[src]1.12.0
pub fn into_key(self) -> K
Take ownership of the key.
Examples
use std::collections::HashMap; use std::collections::hash_map::Entry; let mut map: HashMap<&str, u32> = HashMap::new(); if let Entry::Vacant(v) = map.entry("poneyland") { v.into_key(); }
pub fn insert(self, value: V) -> &'a mut V
Sets the value of the entry with the VacantEntry
’s key, and returns a mutable reference to it.
Examples
use std::collections::HashMap; use std::collections::hash_map::Entry; let mut map: HashMap<&str, u32> = HashMap::new(); if let Entry::Vacant(o) = map.entry("poneyland") { o.insert(37); } assert_eq!(map["poneyland"], 37);
Trait Implementations
[src]1.12.0
impl<K: Debug, V> Debug for VacantEntry<'_, K, V>
Auto Trait Implementations
impl<'a, K, V> RefUnwindSafe for VacantEntry<'a, K, V> where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<'a, K, V> Unpin for VacantEntry<'a, K, V> where
K: Unpin,
impl<'a, K, V> !UnwindSafe for VacantEntry<'a, K, V>
Blanket Implementations
impl<T> From<T> for T
pub fn from(t: T) -> T
Performs the conversion.
pub fn into(self) -> U
Performs the conversion.
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/collections/hash_map/struct.VacantEntry.html