pub struct KV {
pub kv: HashMap<String, KvValue>,
}
Expand description
A simple key-value storage
Keeps pairs of (&'static str, KvValue)
and is used to pass key-value pairs to
Observers
in each iteration of an optimization algorithm.
Typically constructed using the kv!
macro.
§Example
use argmin::kv;
let kv = kv!(
"key1" => "value1";
"key2" => "value2";
"key3" => 1234;
);
Fields§
§kv: HashMap<String, KvValue>
The actual key value storage
Implementations§
source§impl KV
impl KV
sourcepub fn insert<T: AsRef<str>>(&mut self, key: T, val: KvValue) -> &mut Self
pub fn insert<T: AsRef<str>>(&mut self, key: T, val: KvValue) -> &mut Self
Insert a key-value pair
§Example
let mut kv = KV::new();
kv.insert("key1", KvValue::Str("value".to_string()));
kv.insert("key2", KvValue::Int(1234));
sourcepub fn get<T: AsRef<str>>(&self, key: T) -> Option<&KvValue>
pub fn get<T: AsRef<str>>(&self, key: T) -> Option<&KvValue>
Retrieve an element from the KV by key
Returns Some(<reference to KvValue>)
if key
is present and None
otherwise.
§Example
let mut kv1 = KV::new();
kv1.insert("key1", KvValue::Float(12.0));
assert_eq!(kv1.get("key1"), Some(&KvValue::Float(12.0)));
assert_eq!(kv1.get("non_existing"), None);
Trait Implementations§
source§impl<'de> Deserialize<'de> for KV
impl<'de> Deserialize<'de> for KV
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>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Extend<(&'static str, KvValue)> for KV
impl Extend<(&'static str, KvValue)> for KV
source§fn extend<I: IntoIterator<Item = (&'static str, KvValue)>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = (&'static str, KvValue)>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
impl StructuralPartialEq for KV
Auto Trait Implementations§
impl Freeze for KV
impl RefUnwindSafe for KV
impl Send for KV
impl Sync for KV
impl Unpin for KV
impl UnwindSafe for KV
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
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.