[][src]Enum cfgmap::CfgValue

pub enum CfgValue {
    Int(i64),
    Float(f64),
    Str(String),
    Bool(bool),
    Map(CfgMap),
    List(Vec<CfgValue>),
    Datetime(Datetime),
    Null,
}

Represents a value within a CfgMap

Variants

Int(i64)

Represents an integer value.

Float(f64)

Represents a float value.

Str(String)

Represents a string.

Bool(bool)

Represents a bool.

Map(CfgMap)

Represents a nested configuration map.

List(Vec<CfgValue>)

Represents a list of values. These values can have differing types.

Datetime(Datetime)

Represents a Datetime. Only available if using from_toml.

Null

Represents a null value. Only available if using from_json.

Methods

impl CfgValue[src]

pub fn get(&self, key: &str) -> Option<&CfgValue>[src]

Assumes the value is a CfgMap and attempts to execute .get() on it. Returns None if the value isn't a CfgMap, or for any reasons .get() may return None.

pub fn get_mut(&mut self, key: &str) -> Option<&mut CfgValue>[src]

Assumes the value is a CfgMap and attempts to execute .get_mut() on it. Returns None if the value isn't a CfgMap, or for any reasons .get_mut() may return None.

pub fn generate_int(&self) -> Option<i64>[src]

Generates an integer using the value, using rand. There are 3 total cases this function handles:

  • Int(x): returns x
  • List([Int(x)]): returns x
  • List([Int(x),Int(y)]): returns an integer between x and y.
  • Else: returns None.

Examples:

 
let num = Int(5);
let vnum = List(vec![Int(10)]);
let range = List(vec![Int(10), Int(20)]);
 
assert_eq!(5, num.generate_int().unwrap());
assert_eq!(10, vnum.generate_int().unwrap());
 
let generated = range.generate_int().unwrap();
assert!((generated >= 10) & (generated < 20));

pub fn generate_float(&self) -> Option<f64>[src]

Generates an float using the value, using rand. There are 3 total cases this function handles:

  • Float(x): returns x
  • List([Float(x)]): returns x
  • List([Float(x),Float(y)]): returns an integer between x and y.
  • Else: returns None.

Examples:

 
let num = Float(5.0);
let vnum = List(vec![Float(10.0)]);
let range = List(vec![Float(10.0), Float(20.0)]);
 
assert_eq!(5.0, num.generate_float().unwrap());
assert_eq!(10.0, vnum.generate_float().unwrap());
 
let generated = range.generate_float().unwrap();
assert!((generated >= 10.0) & (generated < 20.0));

pub fn to_int(&self) -> Option<i64>[src]

Returns the contents of the enum converted into an integer, if possible.

If the enum represents a float, it will be converted into an integer.

pub fn to_float(&self) -> Option<f64>[src]

Returns the contents of the enum converted into a float, if possible.

If the enum represents an integer, it will be converted into a float.

pub fn is_int(&self) -> bool[src]

Checks whether the enum is a CfgValue::Int.

pub fn is_float(&self) -> bool[src]

Checks whether the enum is a CfgValue::Float.

pub fn is_str(&self) -> bool[src]

Checks whether the enum is a CfgValue::Str.

pub fn is_bool(&self) -> bool[src]

Checks whether the enum is a CfgValue::Bool.

pub fn is_map(&self) -> bool[src]

Checks whether the enum is a CfgValue::Map.

pub fn is_list(&self) -> bool[src]

Checks whether the enum is a CfgValue::List.

pub fn is_null(&self) -> bool[src]

Checks whether the enum is a CfgValue::Null.

pub fn is_datetime(&self) -> bool[src]

Checks whether the enum is a CfgValue::Datetime.

pub fn as_int(&self) -> Option<&i64>[src]

Returns a reference to the _Int. Result is None if contents aren't a CfgValue::Int.

pub fn as_float(&self) -> Option<&f64>[src]

Returns a reference to the _Float. Result is None if contents aren't a CfgValue::Float.

pub fn as_str(&self) -> Option<&String>[src]

Returns a reference to the _Str. Result is None if contents aren't a CfgValue::Str.

pub fn as_bool(&self) -> Option<&bool>[src]

Returns a reference to the _Bool. Result is None if contents aren't a CfgValue::Bool.

pub fn as_map(&self) -> Option<&CfgMap>[src]

Returns a reference to the CfgMap. Result is None if contents aren't a CfgValue::Map.

pub fn as_list(&self) -> Option<&Vec<CfgValue>>[src]

Returns a reference to the Vec<CfgValue>. Result is None if contents aren't a CfgValue::List.

pub fn as_int_mut(&mut self) -> Option<&mut i64>[src]

Returns a reference to the _Int. Result is None if contents aren't a CfgValue::Int.

pub fn as_float_mut(&mut self) -> Option<&mut f64>[src]

Returns a reference to the _Float. Result is None if contents aren't a CfgValue::Float.

pub fn as_str_mut(&mut self) -> Option<&mut String>[src]

Returns a reference to the _Str. Result is None if contents aren't a CfgValue::Str.

pub fn as_bool_mut(&mut self) -> Option<&mut bool>[src]

Returns a reference to the _Bool. Result is None if contents aren't a CfgValue::Bool.

pub fn as_map_mut(&mut self) -> Option<&mut CfgMap>[src]

Returns a reference to the CfgMap. Result is None if contents aren't a CfgValue::Map.

pub fn as_list_mut(&mut self) -> Option<&mut Vec<CfgValue>>[src]

Returns a reference to the Vec<CfgValue>. Result is None if contents aren't a CfgValue::List.

Trait Implementations

impl Checkable for CfgValue[src]

impl Clone for CfgValue[src]

impl Debug for CfgValue[src]

impl<'_> From<&'_ str> for CfgValue[src]

impl From<CfgMap> for CfgValue[src]

impl From<Option<CfgValue>> for CfgValue[src]

impl From<String> for CfgValue[src]

impl From<Vec<CfgValue>> for CfgValue[src]

impl From<bool> for CfgValue[src]

impl From<f32> for CfgValue[src]

impl From<f64> for CfgValue[src]

impl From<i16> for CfgValue[src]

impl From<i32> for CfgValue[src]

impl From<i64> for CfgValue[src]

impl From<i8> for CfgValue[src]

impl From<u16> for CfgValue[src]

impl From<u32> for CfgValue[src]

impl From<u8> for CfgValue[src]

impl PartialEq<CfgValue> for CfgValue[src]

impl StructuralPartialEq for CfgValue[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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