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 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