#[non_exhaustive]pub enum Value {
Null,
Bool(bool),
Integer(i64),
Float(f64),
String(String),
Array(Vec<Value>),
Object(IndexMap<String, Value>),
}Expand description
Unified data model for all supported formats.
Every data format (JSON, CSV, YAML, TOML, XML, etc.) is converted to and from this common representation. The variants cover all primitive and composite data types needed for lossless round-trip conversion.
§Examples
use dkit_core::value::Value;
let v = Value::Integer(42);
assert_eq!(v.as_i64(), Some(42));
assert!(v.as_str().is_none());Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Null
JSON null / missing value.
Bool(bool)
Boolean value.
Integer(i64)
64-bit signed integer.
Float(f64)
64-bit floating-point number.
String(String)
UTF-8 string.
Array(Vec<Value>)
Ordered sequence of values.
Object(IndexMap<String, Value>)
Ordered map of string keys to values (insertion order preserved).
Implementations§
Source§impl Value
impl Value
Sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
Returns the boolean value if this is a Bool, otherwise None.
Sourcepub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
Returns the integer value if this is an Integer, otherwise None.
Sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
Returns the value as f64. Works for both Float and Integer variants.
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Returns a string slice if this is a String, otherwise None.
Sourcepub fn as_array(&self) -> Option<&Vec<Value>>
pub fn as_array(&self) -> Option<&Vec<Value>>
Returns a reference to the inner Vec if this is an Array, otherwise None.