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