pub enum RawEntryMut<'a, K: 'a, V: 'a, S: 'a> {
    Occupied(RawOccupiedEntryMut<'a, K, V, S>),
    Vacant(RawVacantEntryMut<'a, K, V, S>),
}
🔬This is a nightly-only experimental API. (hash_raw_entry #56167)
Expand description

map 中单个条目的视图,该条目可能是空的或被已占用。

这是 Entry 的较低版本。

enum 是通过 HashMap 上的 raw_entry_mut 方法构造的,然后调用该 RawEntryBuilderMut 的方法之一。

Variants§

§

Occupied(RawOccupiedEntryMut<'a, K, V, S>)

🔬This is a nightly-only experimental API. (hash_raw_entry #56167)

一个被占用的条目。

§

Vacant(RawVacantEntryMut<'a, K, V, S>)

🔬This is a nightly-only experimental API. (hash_raw_entry #56167)

一个空的条目。

Implementations§

source§

impl<'a, K, V, S> RawEntryMut<'a, K, V, S>

source

pub fn or_insert(self, default_key: K, default_val: V) -> (&'a mut K, &'a mut V)where K: Hash, S: BuildHasher,

🔬This is a nightly-only experimental API. (hash_raw_entry #56167)

通过插入默认值 (如果为空) 来确保值在条目中,并向条目中的键和值返回可变引用。

Examples
#![feature(hash_raw_entry)]
use std::collections::HashMap;

let mut map: HashMap<&str, u32> = HashMap::new();

map.raw_entry_mut().from_key("poneyland").or_insert("poneyland", 3);
assert_eq!(map["poneyland"], 3);

*map.raw_entry_mut().from_key("poneyland").or_insert("poneyland", 10).1 *= 2;
assert_eq!(map["poneyland"], 6);
Run
source

pub fn or_insert_with<F>(self, default: F) -> (&'a mut K, &'a mut V)where F: FnOnce() -> (K, V), K: Hash, S: BuildHasher,

🔬This is a nightly-only experimental API. (hash_raw_entry #56167)

通过插入默认函数 (如果为空) 的结果来确保值在条目中,并在条目中的键和值上返回变量引用。

Examples
#![feature(hash_raw_entry)]
use std::collections::HashMap;

let mut map: HashMap<&str, String> = HashMap::new();

map.raw_entry_mut().from_key("poneyland").or_insert_with(|| {
    ("poneyland", "hoho".to_string())
});

assert_eq!(map["poneyland"], "hoho".to_string());
Run
source

pub fn and_modify<F>(self, f: F) -> Selfwhere F: FnOnce(&mut K, &mut V),

🔬This is a nightly-only experimental API. (hash_raw_entry #56167)

在任何潜在的插入 map 之前,提供对占用条目的就地可变访问。

Examples
#![feature(hash_raw_entry)]
use std::collections::HashMap;

let mut map: HashMap<&str, u32> = HashMap::new();

map.raw_entry_mut()
   .from_key("poneyland")
   .and_modify(|_k, v| { *v += 1 })
   .or_insert("poneyland", 42);
assert_eq!(map["poneyland"], 42);

map.raw_entry_mut()
   .from_key("poneyland")
   .and_modify(|_k, v| { *v += 1 })
   .or_insert("poneyland", 0);
assert_eq!(map["poneyland"], 43);
Run

Trait Implementations§

source§

impl<K: Debug, V: Debug, S> Debug for RawEntryMut<'_, K, V, S>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

使用给定的格式化程序格式化该值。 Read more

Auto Trait Implementations§

§

impl<'a, K, V, S> RefUnwindSafe for RawEntryMut<'a, K, V, S>where K: RefUnwindSafe, S: RefUnwindSafe, V: RefUnwindSafe,

§

impl<'a, K, V, S> Send for RawEntryMut<'a, K, V, S>where K: Send, S: Send + Sync, V: Send,

§

impl<'a, K, V, S> Sync for RawEntryMut<'a, K, V, S>where K: Sync, S: Sync, V: Sync,

§

impl<'a, K, V, S> Unpin for RawEntryMut<'a, K, V, S>

§

impl<'a, K, V, S> !UnwindSafe for RawEntryMut<'a, K, V, S>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

获取 selfTypeIdRead more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

从拥有的值中一成不变地借用。 Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

从拥有的值中借用。 Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

返回未更改的参数。

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

调用 U::from(self)

也就是说,这种转换是 From<T> for U 实现选择执行的任何操作。

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

发生转换错误时返回的类型。
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

执行转换。
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

发生转换错误时返回的类型。
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

执行转换。