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<&'static str, KvValue>
The actual key value storage
Implementations§
source§impl KV
impl KV
sourcepub fn insert(&mut self, key: &'static str, val: KvValue) -> &mut Self
pub fn insert(&mut self, key: &'static str, 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(&self, key: &'static str) -> Option<&KvValue>
pub fn get(&self, key: &'static str) -> 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 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