pub struct KV {
    pub kv: HashMap<&'static str, KVType>,
}
Expand description

A simple key-value storage

Keeps pairs of (&'static str, KVType) 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, KVType>

The actual key value storage

Implementations

Constructor a new empty KV

Example
let kv = KV::new();

Insert a key-value pair

Example
let mut kv = KV::new();
kv.insert("key1", KVType::Str("value".to_string()));
kv.insert("key2", KVType::Int(1234));

Retrieve an element from the KV by key

Returns Some(<reference to KVType>) if key is present and None otherwise.

Example
let mut kv1 = KV::new();
kv1.insert("key1", KVType::Float(12.0));

assert_eq!(kv1.get("key1"), Some(&KVType::Float(12.0)));
assert_eq!(kv1.get("non_existing"), None);

Returns all available keys and their KVType kind

Example
let mut kv1 = KV::new();
kv1.insert("key1", KVType::Str("value1".to_string()));

assert_eq!(kv1.keys(), vec![("key1", "Str")]);

Merge with another KV

Example
let mut kv1 = KV::new();
kv1.insert("key1", KVType::Str("value1".to_string()));

let mut kv2 = KV::new();
kv2.insert("key2", KVType::Str("value2".to_string()));

let kv1 = kv1.merge(kv2);

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Formats the value using the given formatter. Read more
Extends a collection with the contents of an iterator. Read more
🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Creates a value from an iterator. Read more
Serialize self into Serializer Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Checks if self is actually part of its subset T (and can be converted to it).
Use with care! Same as self.to_subset but without any property checks. Always succeeds.
The inclusion map: converts self to the equivalent element of its superset.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.