从HashMap中获取所拥有的值是否有比这行代码更有效率的方式?
let output_items = output_tables.get(TABLE_NAME_TLIST).unwrap().to_owned();
这个屏幕截图用于扩展类型:
从HashMap中获取所拥有的值是否有比这行代码更有效率的方式?
let output_items = output_tables.get(TABLE_NAME_TLIST).unwrap().to_owned();
这个屏幕截图用于扩展类型:
如果您想拥有该值的所有权,HashMap::remove()
将返回一个 Option<T>
而不是由 HashMap::get()
返回的 Option<&T>
。请参见此播放区:
use std::collections::HashMap;
fn main() {
let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.remove(&1), Some("a"));
assert_eq!(map.remove(&1), None);
}