pub enum ConfigValue {
String(String),
Integer(i64),
Float(f64),
Boolean(bool),
Array(Vec<ConfigValue>),
Object(HashMap<String, ConfigValue>),
}Expand description
Configuration value types
ConfigValue represents different types of configuration values
that can be stored and retrieved from the configuration system.
Variants§
String(String)
String value
Integer(i64)
Integer value
Float(f64)
Float value
Boolean(bool)
Boolean value
Array(Vec<ConfigValue>)
Array of values
Object(HashMap<String, ConfigValue>)
Nested object/map
Implementations§
Source§impl ConfigValue
impl ConfigValue
Sourcepub fn as_string(&self) -> Option<String>
pub fn as_string(&self) -> Option<String>
Converts the value to a string if possible
§Examples
use verdure_context::ConfigValue;
let value = ConfigValue::String("hello".to_string());
assert_eq!(value.as_string(), Some("hello".to_string()));
let value = ConfigValue::Integer(42);
assert_eq!(value.as_string(), Some("42".to_string()));Sourcepub fn as_integer(&self) -> Option<i64>
pub fn as_integer(&self) -> Option<i64>
Converts the value to an integer if possible
§Examples
use verdure_context::ConfigValue;
let value = ConfigValue::Integer(42);
assert_eq!(value.as_integer(), Some(42));
let value = ConfigValue::String("123".to_string());
assert_eq!(value.as_integer(), Some(123));Sourcepub fn as_float(&self) -> Option<f64>
pub fn as_float(&self) -> Option<f64>
Converts the value to a float if possible
§Examples
use verdure_context::ConfigValue;
let value = ConfigValue::Float(3.14);
assert_eq!(value.as_float(), Some(3.14));
let value = ConfigValue::Integer(42);
assert_eq!(value.as_float(), Some(42.0));Sourcepub fn as_boolean(&self) -> Option<bool>
pub fn as_boolean(&self) -> Option<bool>
Converts the value to a boolean if possible
§Examples
use verdure_context::ConfigValue;
let value = ConfigValue::Boolean(true);
assert_eq!(value.as_boolean(), Some(true));
let value = ConfigValue::String("true".to_string());
assert_eq!(value.as_boolean(), Some(true));Sourcepub fn as_array(&self) -> Option<&Vec<ConfigValue>>
pub fn as_array(&self) -> Option<&Vec<ConfigValue>>
Converts the value to an array if possible
§Examples
use verdure_context::ConfigValue;
let value = ConfigValue::Array(vec![
ConfigValue::String("a".to_string()),
ConfigValue::String("b".to_string()),
]);
assert!(value.as_array().is_some());Sourcepub fn as_object(&self) -> Option<&HashMap<String, ConfigValue>>
pub fn as_object(&self) -> Option<&HashMap<String, ConfigValue>>
Converts the value to an object/map if possible
§Examples
use verdure_context::ConfigValue;
use std::collections::HashMap;
let mut obj = HashMap::new();
obj.insert("key".to_string(), ConfigValue::String("value".to_string()));
let value = ConfigValue::Object(obj);
assert!(value.as_object().is_some());Trait Implementations§
Source§impl Clone for ConfigValue
impl Clone for ConfigValue
Source§fn clone(&self) -> ConfigValue
fn clone(&self) -> ConfigValue
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ConfigValue
impl Debug for ConfigValue
Source§impl<'de> Deserialize<'de> for ConfigValue
impl<'de> Deserialize<'de> for ConfigValue
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for ConfigValue
impl RefUnwindSafe for ConfigValue
impl Send for ConfigValue
impl Sync for ConfigValue
impl Unpin for ConfigValue
impl UnsafeUnpin for ConfigValue
impl UnwindSafe for ConfigValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more