pub enum Value {
Null,
Bool(bool),
String(String),
Integer(i64),
Float(f64),
Array(Vec<Value>),
Map(Vec<(String, Value)>),
}Expand description
Represents a unified configuration value.
This enum provides a common representation for values from different configuration formats (JSON, YAML, TOML, etc.).
§Examples
use bare_config::value::Value;
let value = Value::String("hello".to_string());
assert!(value.is_string());
let value = Value::integer(42);
assert!(value.is_number());Variants§
Null
Null value (JSON null, YAML null, etc.)
Bool(bool)
Boolean value (true or false)
String(String)
String value
Integer(i64)
Integer number value
Float(f64)
Floating-point number value
Array(Vec<Value>)
Array value
Map(Vec<(String, Value)>)
Object/value map (JSON object, YAML mapping, etc.)
Implementations§
Source§impl Value
impl Value
Sourcepub fn null() -> Self
pub fn null() -> Self
Creates a new Null value.
§Examples
use bare_config::value::Value;
let value = Value::null();
assert!(value.is_null());Sourcepub fn bool(b: bool) -> Self
pub fn bool(b: bool) -> Self
Creates a new Boolean value.
§Examples
use bare_config::value::Value;
let value = Value::bool(true);
assert_eq!(value.as_bool(), Some(true));Sourcepub fn string<S: Into<String>>(s: S) -> Self
pub fn string<S: Into<String>>(s: S) -> Self
Creates a new String value.
§Examples
use bare_config::value::Value;
let value = Value::string("hello");
assert_eq!(value.as_str(), Some("hello"));Sourcepub fn integer(i: i64) -> Self
pub fn integer(i: i64) -> Self
Creates a new Integer value.
§Examples
use bare_config::value::Value;
let value = Value::integer(42);
assert_eq!(value.as_integer(), Some(42));Sourcepub fn float(f: f64) -> Self
pub fn float(f: f64) -> Self
Creates a new Float value.
§Examples
use bare_config::value::Value;
let value = Value::float(3.14);
assert_eq!(value.as_float(), Some(3.14));Sourcepub fn array(v: Vec<Value>) -> Self
pub fn array(v: Vec<Value>) -> Self
Creates a new Array value.
§Examples
use bare_config::value::Value;
let value = Value::array(vec![
Value::integer(1),
Value::integer(2),
]);
assert!(value.is_array());Sourcepub fn map(m: Vec<(String, Value)>) -> Self
pub fn map(m: Vec<(String, Value)>) -> Self
Creates a new Map value.
§Examples
use bare_config::value::Value;
let value = Value::map(vec![
("key".to_string(), Value::string("value".to_string())),
]);
assert!(value.is_map());Sourcepub fn is_null(&self) -> bool
pub fn is_null(&self) -> bool
Returns true if this value is Null.
§Examples
use bare_config::value::Value;
let value = Value::null();
assert!(value.is_null());
let value = Value::string("test");
assert!(!value.is_null());Sourcepub fn is_bool(&self) -> bool
pub fn is_bool(&self) -> bool
Returns true if this value is a Boolean.
§Examples
use bare_config::value::Value;
let value = Value::bool(true);
assert!(value.is_bool());Sourcepub fn is_string(&self) -> bool
pub fn is_string(&self) -> bool
Returns true if this value is a String.
§Examples
use bare_config::value::Value;
let value = Value::string("test");
assert!(value.is_string());Sourcepub fn is_number(&self) -> bool
pub fn is_number(&self) -> bool
Returns true if this value is a Number (Integer or Float).
§Examples
use bare_config::value::Value;
let value = Value::integer(42);
assert!(value.is_number());
let value = Value::float(3.14);
assert!(value.is_number());Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Returns true if this value is an Integer.
§Examples
use bare_config::value::Value;
let value = Value::integer(42);
assert!(value.is_integer());Sourcepub fn is_float(&self) -> bool
pub fn is_float(&self) -> bool
Returns true if this value is a Float.
§Examples
use bare_config::value::Value;
let value = Value::float(3.14);
assert!(value.is_float());Sourcepub fn is_array(&self) -> bool
pub fn is_array(&self) -> bool
Returns true if this value is an Array.
§Examples
use bare_config::value::Value;
let value = Value::array(vec![]);
assert!(value.is_array());Sourcepub fn is_map(&self) -> bool
pub fn is_map(&self) -> bool
Returns true if this value is a Map.
§Examples
use bare_config::value::Value;
let value = Value::map(vec![]);
assert!(value.is_map());Sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
Returns the Boolean value if this is a Boolean.
§Examples
use bare_config::value::Value;
let value = Value::bool(true);
assert_eq!(value.as_bool(), Some(true));Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Returns the String value if this is a String.
§Examples
use bare_config::value::Value;
let value = Value::string("hello");
assert_eq!(value.as_str(), Some("hello"));Sourcepub fn as_integer(&self) -> Option<i64>
pub fn as_integer(&self) -> Option<i64>
Returns the Integer value if this is an Integer.
§Examples
use bare_config::value::Value;
let value = Value::integer(42);
assert_eq!(value.as_integer(), Some(42));Sourcepub fn as_u16(&self) -> Option<u16>
pub fn as_u16(&self) -> Option<u16>
Returns the value as u16 if this is an Integer value within range.
Unlike to_u16, this method only works on Integer values
and does not attempt to parse strings.
Sourcepub fn to_u16(&self) -> Option<u16>
pub fn to_u16(&self) -> Option<u16>
Attempts to convert this value into u16.
This accepts integer values directly and parses string values.
Unlike as_u16, this also works on String values.
Sourcepub fn as_float(&self) -> Option<f64>
pub fn as_float(&self) -> Option<f64>
Returns the Float value if this is a Float.
§Examples
use bare_config::value::Value;
let value = Value::float(3.14);
assert_eq!(value.as_float(), Some(3.14));Sourcepub fn as_array(&self) -> Option<&Vec<Value>>
pub fn as_array(&self) -> Option<&Vec<Value>>
Returns the Array value if this is an Array.
§Examples
use bare_config::value::Value;
let value = Value::array(vec![Value::integer(1)]);
let arr = value.as_array().unwrap();
assert_eq!(arr.len(), 1);Sourcepub fn as_map(&self) -> Option<&Vec<(String, Value)>>
pub fn as_map(&self) -> Option<&Vec<(String, Value)>>
Returns the Map value if this is a Map.
§Examples
use bare_config::value::Value;
let value = Value::map(vec![("key".to_string(), Value::string("value".to_string()))]);
let map = value.as_map().unwrap();
assert_eq!(map.len(), 1);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in this value.
For Array, returns the number of elements. For Map, returns the number of key-value pairs. For other types, returns 0.
§Examples
use bare_config::value::Value;
let value = Value::array(vec![Value::integer(1), Value::integer(2)]);
assert_eq!(value.len(), 2);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if this value has no elements.
§Examples
use bare_config::value::Value;
let value = Value::array(vec![]);
assert!(value.is_empty());Sourcepub fn to_string_repr(&self) -> String
pub fn to_string_repr(&self) -> String
Converts the value to a string representation.
§Examples
use bare_config::value::Value;
let value = Value::string("hello");
assert_eq!(value.to_string_repr(), "hello");
let value = Value::integer(42);
assert_eq!(value.to_string_repr(), "42");