Struct argmin::core::KV

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

source

pub fn new() -> Self

Constructor a new empty KV

§Example
let kv = KV::new();
source

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));
source

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);
source

pub fn keys(&self) -> Vec<(String, &'static str)>

Returns all available keys and their KvValue kind

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

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

pub fn merge(self, other: KV) -> Self

Merge with another KV

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

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

let kv1 = kv1.merge(kv2);

Trait Implementations§

source§

impl Clone for KV

source§

fn clone(&self) -> KV

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for KV

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for KV

source§

fn default() -> KV

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for KV

source§

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 Display for KV

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Extend<(&'static str, KvValue)> for KV

source§

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)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

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

impl FromIterator<(&'static str, KvValue)> for KV

source§

fn from_iter<I: IntoIterator<Item = (&'static str, KvValue)>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl PartialEq for KV

source§

fn eq(&self, other: &KV) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for KV

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> Same for T

source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

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

Checks if self is actually part of its subset T (and can be converted to it).
§

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

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

source§

impl<T> SendAlias for T

source§

impl<T> SyncAlias for T