本文簡要介紹rust語言中 std::collections::hash_set::HashSet.replace
的用法。
用法
pub fn replace(&mut self, value: T) -> Option<T>
向集合中添加一個值,替換等於給定值的現有值(如果有)。返回替換的值。
例子
use std::collections::HashSet;
let mut set = HashSet::new();
set.insert(Vec::<i32>::new());
assert_eq!(set.get(&[][..]).unwrap().capacity(), 0);
set.replace(Vec::with_capacity(10));
assert_eq!(set.get(&[][..]).unwrap().capacity(), 10);
相關用法
- Rust HashSet.remove用法及代碼示例
- Rust HashSet.reserve用法及代碼示例
- Rust HashSet.retain用法及代碼示例
- Rust HashSet.get_or_insert_with用法及代碼示例
- Rust HashSet.insert用法及代碼示例
- Rust HashSet.get_or_insert用法及代碼示例
- Rust HashSet.is_superset用法及代碼示例
- Rust HashSet.shrink_to用法及代碼示例
- Rust HashSet.with_hasher用法及代碼示例
- Rust HashSet.with_capacity用法及代碼示例
- Rust HashSet.difference用法及代碼示例
- Rust HashSet.try_reserve用法及代碼示例
- Rust HashSet.hasher用法及代碼示例
- Rust HashSet.drain_filter用法及代碼示例
- Rust HashSet.get用法及代碼示例
- Rust HashSet.is_empty用法及代碼示例
- Rust HashSet.shrink_to_fit用法及代碼示例
- Rust HashSet.len用法及代碼示例
- Rust HashSet.drain用法及代碼示例
- Rust HashSet.new用法及代碼示例
- Rust HashSet.with_capacity_and_hasher用法及代碼示例
- Rust HashSet.contains用法及代碼示例
- Rust HashSet.clear用法及代碼示例
- Rust HashSet.union用法及代碼示例
- Rust HashSet.is_subset用法及代碼示例
注:本文由純淨天空篩選整理自rust-lang.org大神的英文原創作品 std::collections::hash_set::HashSet.replace。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。