Enum argmin::core::KvValue

source ·
pub enum KvValue {
    Float(f64),
    Int(i64),
    Uint(u64),
    Bool(bool),
    Str(String),
}
Expand description

Types available for use in KV.

Float, Int and Uint are all 64bit. The corresponding 32bit variants must be be converted to 64 bit. Preferably the From impls are used to create a KvValue:

let x: KvValue = 1u64.into();
assert_eq!(x, KvValue::Uint(1u64));

let x: KvValue = 2u32.into();
assert_eq!(x, KvValue::Uint(2u64));

let x: KvValue = 2i64.into();
assert_eq!(x, KvValue::Int(2i64));

let x: KvValue = 2i32.into();
assert_eq!(x, KvValue::Int(2i64));

let x: KvValue = 1.0f64.into();
assert_eq!(x, KvValue::Float(1f64));

let x: KvValue = 1.0f32.into();
assert_eq!(x, KvValue::Float(1f64));

let x: KvValue = true.into();
assert_eq!(x, KvValue::Bool(true));

let x: KvValue = "a str".into();
assert_eq!(x, KvValue::Str("a str".to_string()));

let x: KvValue = "a String".to_string().into();
assert_eq!(x, KvValue::Str("a String".to_string()));

Variants§

§

Float(f64)

Floating point values

§

Int(i64)

Signed integers

§

Uint(u64)

Unsigned integers

§

Bool(bool)

Boolean values

§

Str(String)

Strings

Implementations§

source§

impl KvValue

source

pub fn kind(&self) -> &'static str

Returns the kind of the KvValue

§Examples
assert_eq!(KvValue::Float(1.0).kind(), "Float");
assert_eq!(KvValue::Int(1).kind(), "Int");
assert_eq!(KvValue::Uint(1).kind(), "Uint");
assert_eq!(KvValue::Bool(true).kind(), "Bool");
assert_eq!(KvValue::Str("string".to_string()).kind(), "Str");
source

pub fn get_float(&self) -> Option<f64>

Extract float from KvValue

Returns Some(<float>) if KvValue is of kind Float.

Note: For KvValue::Int and KvValue::Uintinteger values are cast to f64, therefore this operation may be lossy!

KvValue::Bool is turned into 1.0f64 if true and 0.0f64 if false.

§Example
assert_eq!(KvValue::Float(1.0).get_float(), Some(1.0));
assert_eq!(KvValue::Int(1).get_float(), Some(1.0));
assert_eq!(KvValue::Uint(1).get_float(), Some(1.0));
assert_eq!(KvValue::Bool(true).get_float(), Some(1.0));
assert_eq!(KvValue::Str("not a number".to_string()).get_float(), None);
source

pub fn get_int(&self) -> Option<i64>

Extract int from KvValue

Returns Some(<int>) if KvValue is of kind Int and None otherwise.

§Example
assert_eq!(KvValue::Int(1).get_int(), Some(1i64));
assert_eq!(KvValue::Float(1.0).get_int(), None);
assert_eq!(KvValue::Uint(1).get_int(), None);
assert_eq!(KvValue::Bool(true).get_int(), None);
assert_eq!(KvValue::Str("not an int".to_string()).get_int(), None);
source

pub fn get_uint(&self) -> Option<u64>

Extract unsigned int from KvValue

Returns Some(<unsigned int>) if KvValue is of kind Uint and None otherwise.

§Example
assert_eq!(KvValue::Uint(1).get_uint(), Some(1u64));
assert_eq!(KvValue::Int(1).get_uint(), None);
assert_eq!(KvValue::Float(1.0).get_uint(), None);
assert_eq!(KvValue::Bool(true).get_uint(), None);
assert_eq!(KvValue::Str("not an uint".to_string()).get_uint(), None);
source

pub fn get_bool(&self) -> Option<bool>

Extract bool from KvValue

Returns Some(<bool>) if KvValue is of kind Bool and None otherwise.

§Example
assert_eq!(KvValue::Bool(true).get_bool(), Some(true));
assert_eq!(KvValue::Float(1.0).get_bool(), None);
assert_eq!(KvValue::Int(1).get_bool(), None);
assert_eq!(KvValue::Uint(1).get_bool(), None);
assert_eq!(KvValue::Str("not a bool".to_string()).get_bool(), None);
source

pub fn get_string(&self) -> Option<String>

Extract String from KvValue

Returns Some(<string>) if KvValue is of kind Str and None otherwise.

§Example
assert_eq!(KvValue::Str("a string".to_string()).get_string(), Some("a string".to_string()));
assert_eq!(KvValue::Float(1.0).get_string(), None);
assert_eq!(KvValue::Int(1).get_string(), None);
assert_eq!(KvValue::Uint(1).get_string(), None);
assert_eq!(KvValue::Bool(true).get_string(), None);
source

pub fn as_string(&self) -> String

Get String representation of KvValue

§Example
assert_eq!(KvValue::Str("a string".to_string()).as_string(), "a string".to_string());
assert_eq!(KvValue::Float(1.0).as_string(), "1".to_string());
assert_eq!(KvValue::Int(1).as_string(), "1".to_string());
assert_eq!(KvValue::Uint(1).as_string(), "1".to_string());
assert_eq!(KvValue::Bool(true).as_string(), "true".to_string());

Trait Implementations§

source§

impl Clone for KvValue

source§

fn clone(&self) -> KvValue

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 KvValue

source§

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

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

impl<'de> Deserialize<'de> for KvValue

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 KvValue

source§

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

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

impl<'a> From<&'a str> for KvValue

source§

fn from(x: &'a str) -> KvValue

Converts to this type from the input type.
source§

impl From<String> for KvValue

source§

fn from(x: String) -> KvValue

Converts to this type from the input type.
source§

impl From<bool> for KvValue

source§

fn from(x: bool) -> KvValue

Converts to this type from the input type.
source§

impl From<f32> for KvValue

source§

fn from(x: f32) -> KvValue

Converts to this type from the input type.
source§

impl From<f64> for KvValue

source§

fn from(x: f64) -> KvValue

Converts to this type from the input type.
source§

impl From<i32> for KvValue

source§

fn from(x: i32) -> KvValue

Converts to this type from the input type.
source§

impl From<i64> for KvValue

source§

fn from(x: i64) -> KvValue

Converts to this type from the input type.
source§

impl From<u32> for KvValue

source§

fn from(x: u32) -> KvValue

Converts to this type from the input type.
source§

impl From<u64> for KvValue

source§

fn from(x: u64) -> KvValue

Converts to this type from the input type.
source§

impl PartialEq for KvValue

source§

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

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

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

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

impl Serialize for KvValue

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 KvValue

Auto Trait Implementations§

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

§

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,

§

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

§

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

§

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