pub struct VacantEntry<'a, K: 'a, V: 'a> { /* fields omitted */ }Expand description
HashMap 中空闲条目的视图。
它是 Entry 枚举的一部分。
获取对通过 VacantEntry 插入值时将使用的键的引用。
use std::collections::HashMap;
let mut map: HashMap<&str, u32> = HashMap::new();
assert_eq!(map.entry("poneyland").key(), &"poneyland");Run 
取得键的所有权。
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();
}Run 
用 VacantEntry 的键设置条目的值,并返回对它的可变引用。
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);Run