pub struct KeyValue<K = String, V = f64> {
pub key: K,
pub value: V,
}Expand description
The KeyValue type is used to generically represent a simple key-value pair within a
store.
Fields§
§key: K§value: VImplementations§
Source§impl<K, V> KeyValue<K, V>
impl<K, V> KeyValue<K, V>
pub const fn new(key: K, value: V) -> Self
Sourcepub fn from_key(key: K) -> Selfwhere
V: Default,
pub fn from_key(key: K) -> Selfwhere
V: Default,
returns a new KeyValue from the given key, using the logical default for the value
Sourcepub fn from_value(value: V) -> Selfwhere
K: Default,
pub fn from_value(value: V) -> Selfwhere
K: Default,
returns a new KeyValue from the given value, using the logical default for the key
Sourcepub fn set_key(&mut self, key: K) -> &mut Self
pub fn set_key(&mut self, key: K) -> &mut Self
update the current key and return a mutable reference to self
Sourcepub fn set_value(&mut self, value: V) -> &mut Self
pub fn set_value(&mut self, value: V) -> &mut Self
update the current value and return a mutable reference to self
Sourcepub fn with_key<K2>(self, key: K2) -> KeyValue<K2, V>
pub fn with_key<K2>(self, key: K2) -> KeyValue<K2, V>
consumes the current instance to create another with the given key
Sourcepub fn with_value<V2>(self, value: V2) -> KeyValue<K, V2>
pub fn with_value<V2>(self, value: V2) -> KeyValue<K, V2>
consumes the current instance to create another with the given value
Sourcepub const fn replace_value(&mut self, value: V) -> V
pub const fn replace_value(&mut self, value: V) -> V
replace the current value and return the old value
Sourcepub const fn swap_value(&mut self, other: &mut KeyValue<K, V>)
pub const fn swap_value(&mut self, other: &mut KeyValue<K, V>)
swap the current value with another in the given instance
Sourcepub fn take_value(&mut self) -> Vwhere
V: Default,
pub fn take_value(&mut self) -> Vwhere
V: Default,
take the current value and return it, replacing it with the
logical default
Sourcepub fn entry(&mut self) -> KeyValue<&K, &mut V>
pub fn entry(&mut self) -> KeyValue<&K, &mut V>
returns a new instance of the KeyValue with mutable references to the value and a
reference to the key
Trait Implementations§
Source§impl<'de, K, V> Deserialize<'de> for KeyValue<K, V>where
K: Deserialize<'de>,
V: Deserialize<'de>,
impl<'de, K, V> Deserialize<'de> for KeyValue<K, V>where
K: Deserialize<'de>,
V: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<K: Ord, V: Ord> Ord for KeyValue<K, V>
impl<K: Ord, V: Ord> Ord for KeyValue<K, V>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<K: PartialOrd, V: PartialOrd> PartialOrd for KeyValue<K, V>
impl<K: PartialOrd, V: PartialOrd> PartialOrd for KeyValue<K, V>
impl<K: Copy, V: Copy> Copy for KeyValue<K, V>
impl<K: Eq, V: Eq> Eq for KeyValue<K, V>
impl<K, V> StructuralPartialEq for KeyValue<K, V>
Auto Trait Implementations§
impl<K, V> Freeze for KeyValue<K, V>
impl<K, V> RefUnwindSafe for KeyValue<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for KeyValue<K, V>
impl<K, V> Sync for KeyValue<K, V>
impl<K, V> Unpin for KeyValue<K, V>
impl<K, V> UnwindSafe for KeyValue<K, V>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CallInPlace<T> for Twhere
T: CallInto<T>,
impl<T> CallInPlace<T> for Twhere
T: CallInto<T>,
Source§fn call_inplace<F>(&mut self, f: F) -> <T as CallInto<T>>::Output
fn call_inplace<F>(&mut self, f: F) -> <T as CallInto<T>>::Output
call_on_mut method allows an object to be passed onto a function that takes a mutable reference
to the object. This is useful for cases where you want to perform an operation on
an object and mutate it in the process.Source§impl<T> CallInto<T> for T
impl<T> CallInto<T> for T
Source§impl<T> CallOn<T> for Twhere
T: CallInto<T>,
impl<T> CallOn<T> for Twhere
T: CallInto<T>,
Source§fn call_on<F>(&self, f: F) -> <T as CallInto<T>>::Output
fn call_on<F>(&self, f: F) -> <T as CallInto<T>>::Output
call_on method allows an object to be passed onto a function that takes a reference
to the object. This is useful for cases where you want to perform an operation on
an object without needing to extract it from a container or context.