Struct argmin::core::KV

source · []
pub struct KV {
    pub kv: Vec<(&'static str, Rc<dyn Display>)>,
}
Expand description

A simple key-value storage

Keeps pairs of (&'static str, Rc<dyn Display>) and is used to pass key-value pairs to Observers in each iteration of an optimization algorithm. Typically constructed using the make_kv! macro.

Example

use argmin::make_kv;

let kv = make_kv!(
    "key1" => "value1";
    "key2" => "value2";
    "key3" => 1234;
);

Fields

kv: Vec<(&'static str, Rc<dyn Display>)>

The actual key value storage

Implementations

Constructor a new empty KV

Example
let kv = KV::new();

Push a key-value pair

Example

let mut kv = KV::new();
kv.push("key", Rc::new("value"));
kv.push("key", Rc::new(1234));

Merge with another KV

Example

let mut kv1 = KV::new();
kv1.push("key1", Rc::new("value1"));

let mut kv2 = KV::new();
kv2.push("key2", Rc::new("value2"));

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

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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.