pub enum Value {
Null,
Bool(bool),
Int(i64),
Float(f64),
String(String),
Date(Date),
Instant(Instant),
Duration(Duration),
Array(Vec<Self>),
Object(Object),
}Expand description
Any SOML value.
let value: soml::Value = "port: 8080\nhosts: ['a', 'b']".parse()?;
assert_eq!(value.get("port").and_then(soml::Value::as_i64), Some(8080));
assert_eq!(value.get("hosts").and_then(|hosts| hosts.get(1)).and_then(soml::Value::as_str), Some("b"));An int and a float are different types, as in the spec: Value::Int(3) and Value::Float(3.0) are not equal, and as_f64() does not convert an int.
Variants§
Null
null.
Bool(bool)
true or false.
Int(i64)
An int.
Float(f64)
A float. A float that came from a document is never NaN, and it is never negative zero.
String(String)
A string.
Date(Date)
A Gregorian calendar date.
Instant(Instant)
An instant.
Duration(Duration)
A duration.
Array(Vec<Self>)
An array.
Object(Object)
An object.
Implementations§
Source§impl Value
impl Value
Sourcepub fn get(&self, index: impl Index) -> Option<&Self>
pub fn get(&self, index: impl Index) -> Option<&Self>
The member of an object with this key, or the item of an array at this position. None for a missing member or item, and for a value of another type.
Sourcepub fn get_mut(&mut self, index: impl Index) -> Option<&mut Self>
pub fn get_mut(&mut self, index: impl Index) -> Option<&mut Self>
A mutable reference to the member of an object with this key, or the item of an array at this position.
Sourcepub const fn as_f64(&self) -> Option<f64>
pub const fn as_f64(&self) -> Option<f64>
The float, if the value is one. An int is not converted, because an int and a float are different types.
Sourcepub const fn as_instant(&self) -> Option<Instant>
pub const fn as_instant(&self) -> Option<Instant>
The instant, if the value is one.
Sourcepub const fn as_duration(&self) -> Option<Duration>
pub const fn as_duration(&self) -> Option<Duration>
The duration, if the value is one.
Sourcepub const fn as_array_mut(&mut self) -> Option<&mut Vec<Self>>
pub const fn as_array_mut(&mut self) -> Option<&mut Vec<Self>>
The items, if the value is an array, to change.
Sourcepub const fn as_object_mut(&mut self) -> Option<&mut Object>
pub const fn as_object_mut(&mut self) -> Option<&mut Object>
The members, if the value is an object, to change.