Movatterモバイル変換


[0]ホーム

URL:


Entry

std::collections::hash_map

EnumEntry 

1.0.0 ·Source
pub enum Entry<'a, K: 'a, V: 'a> {    Occupied(OccupiedEntry<'a, K, V>),    Vacant(VacantEntry<'a, K, V>),}
Expand description

A view into a single entry in a map, which may either be vacant or occupied.

Thisenum is constructed from theentry method onHashMap.

Variants§

§1.0.0

Occupied(OccupiedEntry<'a, K, V>)

An occupied entry.

§1.0.0

Vacant(VacantEntry<'a, K, V>)

A vacant entry.

Implementations§

Source§

impl<'a, K, V>Entry<'a, K, V>

1.0.0 ·Source

pub fnor_insert(self, default: V) ->&'a mut V

Ensures a value is in the entry by inserting the default if empty, and returnsa mutable reference to the value in the entry.

§Examples
usestd::collections::HashMap;letmutmap: HashMap<&str, u32> = HashMap::new();map.entry("poneyland").or_insert(3);assert_eq!(map["poneyland"],3);*map.entry("poneyland").or_insert(10)*=2;assert_eq!(map["poneyland"],6);
1.0.0 ·Source

pub fnor_insert_with<F:FnOnce() -> V>(self, default: F) ->&'a mut V

Ensures a value is in the entry by inserting the result of the default function if empty,and returns a mutable reference to the value in the entry.

§Examples
usestd::collections::HashMap;letmutmap = HashMap::new();letvalue ="hoho";map.entry("poneyland").or_insert_with(|| value);assert_eq!(map["poneyland"],"hoho");
1.50.0 ·Source

pub fnor_insert_with_key<F:FnOnce(&K) -> V>(self, default: F) ->&'a mut V

Ensures a value is in the entry by inserting, if empty, the result of the default function.This method allows for generating key-derived values for insertion by providing the defaultfunction a reference to the key that was moved during the.entry(key) method call.

The reference to the moved key is provided so that cloning or copying the key isunnecessary, unlike with.or_insert_with(|| ... ).

§Examples
usestd::collections::HashMap;letmutmap: HashMap<&str, usize> = HashMap::new();map.entry("poneyland").or_insert_with_key(|key| key.chars().count());assert_eq!(map["poneyland"],9);
1.10.0 ·Source

pub fnkey(&self) ->&K

Returns a reference to this entry’s key.

§Examples
usestd::collections::HashMap;letmutmap: HashMap<&str, u32> = HashMap::new();assert_eq!(map.entry("poneyland").key(),&"poneyland");
1.26.0 ·Source

pub fnand_modify<F>(self, f: F) -> Self
where F:FnOnce(&mut V),

Provides in-place mutable access to an occupied entry before anypotential inserts into the map.

§Examples
usestd::collections::HashMap;letmutmap: HashMap<&str, u32> = HashMap::new();map.entry("poneyland")   .and_modify(|e| {*e +=1})   .or_insert(42);assert_eq!(map["poneyland"],42);map.entry("poneyland")   .and_modify(|e| {*e +=1})   .or_insert(42);assert_eq!(map["poneyland"],43);
1.83.0 ·Source

pub fninsert_entry(self, value: V) ->OccupiedEntry<'a, K, V>

Sets the value of the entry, and returns anOccupiedEntry.

§Examples
usestd::collections::HashMap;letmutmap: HashMap<&str, String> = HashMap::new();letentry = map.entry("poneyland").insert_entry("hoho".to_string());assert_eq!(entry.key(),&"poneyland");
Source§

impl<'a, K, V:Default>Entry<'a, K, V>

1.28.0 ·Source

pub fnor_default(self) ->&'a mut V

Ensures a value is in the entry by inserting the default value if empty,and returns a mutable reference to the value in the entry.

§Examples
usestd::collections::HashMap;letmutmap: HashMap<&str,Option<u32>> = HashMap::new();map.entry("poneyland").or_default();assert_eq!(map["poneyland"],None);

Trait Implementations§

1.12.0 ·Source§

impl<K:Debug, V:Debug>Debug forEntry<'_, K, V>

Source§

fnfmt(&self, f: &mutFormatter<'_>) ->Result

Formats the value using the given formatter.Read more

Auto Trait Implementations§

§

impl<'a, K, V>Freeze forEntry<'a, K, V>
where K:Freeze,

§

impl<'a, K, V>RefUnwindSafe forEntry<'a, K, V>

§

impl<'a, K, V>Send forEntry<'a, K, V>
where K:Send, V:Send,

§

impl<'a, K, V>Sync forEntry<'a, K, V>
where K:Sync, V:Sync,

§

impl<'a, K, V>Unpin forEntry<'a, K, V>
where K:Unpin,

§

impl<'a, K, V> !UnwindSafe forEntry<'a, K, V>

Blanket Implementations§

Source§

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

Source§

fntype_id(&self) ->TypeId

Gets theTypeId ofself.Read more
Source§

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

Source§

fnborrow(&self) ->&T

Immutably borrows from an owned value.Read more
Source§

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

Source§

fnborrow_mut(&mut self) ->&mut T

Mutably borrows from an owned value.Read more
Source§

impl<T>From<T> for T

Source§

fnfrom(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fninto(self) -> U

CallsU::from(self).

That is, this conversion is whatever the implementation ofFrom<T> for U chooses to do.

Source§

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

Source§

typeError =Infallible

The type returned in the event of a conversion error.
Source§

fntry_from(value: U) ->Result<T, <T asTryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

typeError = <U asTryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fntry_into(self) ->Result<U, <U asTryFrom<T>>::Error>

Performs the conversion.

[8]ページ先頭

©2009-2026 Movatter.jp