[−][src]Enum cfgmap::CfgValue
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.
Represents a list of values. These values can have differing types.
Datetime(Datetime)
Represents a Datetime
. Only available if using from_toml
.
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 xList([Int(x)])
: returns xList([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 xList([Float(x)])
: returns xList([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]
fn check_that(&self, c: Condition) -> bool
[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
impl RefUnwindSafe for CfgValue
impl Send for CfgValue
impl Sync for CfgValue
impl Unpin for CfgValue
impl UnwindSafe for CfgValue
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,