pub trait MapEntry<'a>: Sized {
type Key;
type Value: 'a;
// Required methods
fn key(&self) -> &Self::Key;
fn or_insert(self, default: Self::Value) -> &'a mut Self::Value;
fn or_insert_with<F: FnOnce() -> Self::Value>(
self,
default: F,
) -> &'a mut Self::Value;
fn or_default(self) -> &'a mut Self::Value
where Self::Value: Default;
fn and_modify<F: FnOnce(&mut Self::Value)>(self, f: F) -> Self;
}Expand description
Common interface over the native entry types of maps.
Required Associated Types§
Required Methods§
Sourcefn or_insert(self, default: Self::Value) -> &'a mut Self::Value
fn or_insert(self, default: Self::Value) -> &'a mut Self::Value
Inserts the provided value if the entry is vacant, then returns it.
Sourcefn or_insert_with<F: FnOnce() -> Self::Value>(
self,
default: F,
) -> &'a mut Self::Value
fn or_insert_with<F: FnOnce() -> Self::Value>( self, default: F, ) -> &'a mut Self::Value
Inserts a value produced by default if the entry is vacant.
Sourcefn or_default(self) -> &'a mut Self::Value
fn or_default(self) -> &'a mut Self::Value
Inserts the default value if the entry is vacant.
Sourcefn and_modify<F: FnOnce(&mut Self::Value)>(self, f: F) -> Self
fn and_modify<F: FnOnce(&mut Self::Value)>(self, f: F) -> Self
Applies f to the value if the entry is occupied.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<'a, K: 'a, V: 'a> MapEntry<'a> for Entry<'a, K, V>
Available on crate feature std only.
impl<'a, K: 'a, V: 'a> MapEntry<'a> for Entry<'a, K, V>
Available on crate feature
std only.type Key = K
type Value = V
fn key(&self) -> &Self::Key
fn or_insert(self, default: Self::Value) -> &'a mut Self::Value
fn or_insert_with<F: FnOnce() -> Self::Value>( self, default: F, ) -> &'a mut Self::Value
fn or_default(self) -> &'a mut Self::Value
fn and_modify<F: FnOnce(&mut Self::Value)>(self, f: F) -> Self
Source§impl<'a, K: 'a, V: 'a> MapEntry<'a> for Entry<'a, K, V>
Available on crate feature indexmap only.
impl<'a, K: 'a, V: 'a> MapEntry<'a> for Entry<'a, K, V>
Available on crate feature
indexmap only.type Key = K
type Value = V
fn key(&self) -> &Self::Key
fn or_insert(self, default: Self::Value) -> &'a mut Self::Value
fn or_insert_with<F: FnOnce() -> Self::Value>( self, default: F, ) -> &'a mut Self::Value
fn or_default(self) -> &'a mut Self::Value
fn and_modify<F: FnOnce(&mut Self::Value)>(self, f: F) -> Self
Source§impl<'a, K: Eq + Hash + 'a, V: 'a, const N: usize> MapEntry<'a> for Entry<'a, K, V, N>
Available on crate feature heapless only.
impl<'a, K: Eq + Hash + 'a, V: 'a, const N: usize> MapEntry<'a> for Entry<'a, K, V, N>
Available on crate feature
heapless only.type Key = K
type Value = V
fn key(&self) -> &Self::Key
fn or_insert(self, default: Self::Value) -> &'a mut Self::Value
fn or_insert_with<F: FnOnce() -> Self::Value>( self, default: F, ) -> &'a mut Self::Value
fn or_default(self) -> &'a mut Self::Value
fn and_modify<F: FnOnce(&mut Self::Value)>(self, f: F) -> Self
Source§impl<'a, K: Hash + 'a, V: 'a, S: BuildHasher + 'a, A: Allocator + 'a> MapEntry<'a> for Entry<'a, K, V, S, A>
Available on crate feature hashbrown only.
impl<'a, K: Hash + 'a, V: 'a, S: BuildHasher + 'a, A: Allocator + 'a> MapEntry<'a> for Entry<'a, K, V, S, A>
Available on crate feature
hashbrown only.type Key = K
type Value = V
fn key(&self) -> &Self::Key
fn or_insert(self, default: Self::Value) -> &'a mut Self::Value
fn or_insert_with<F: FnOnce() -> Self::Value>( self, default: F, ) -> &'a mut Self::Value
fn or_default(self) -> &'a mut Self::Value
fn and_modify<F: FnOnce(&mut Self::Value)>(self, f: F) -> Self
Source§impl<'a, K: Ord + 'a, V: 'a> MapEntry<'a> for Entry<'a, K, V>
Available on crate feature alloc only.
impl<'a, K: Ord + 'a, V: 'a> MapEntry<'a> for Entry<'a, K, V>
Available on crate feature
alloc only.