当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Rust OccupiedEntry.remove用法及代码示例


本文简要介绍rust语言中 alloc::collections::btree_map::OccupiedEntry.remove 的用法。

用法

pub fn remove(self) -> V

从映射中取出条目的值,并将其返回。

例子

use std::collections::BTreeMap;
use std::collections::btree_map::Entry;

let mut map: BTreeMap<&str, usize> = BTreeMap::new();
map.entry("poneyland").or_insert(12);

if let Entry::Occupied(o) = map.entry("poneyland") {
    assert_eq!(o.remove(), 12);
}
// If we try to get "poneyland"'s value, it'll panic:
// println!("{}", map["poneyland"]);

相关用法


注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 alloc::collections::btree_map::OccupiedEntry.remove。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。