pub enum LazyValue<'a> {
Null,
Raw(Raw<'a>),
Array(Array<'a>),
Object(Object<'a>),
String(String<'a>),
Number(Number),
Boolean(bool),
}Expand description
Represents a lazy JSON value.
The initial value will always be Value::Raw until you call its mutating APIs.
Variants§
Null
Represents a JSON null value.
Raw(Raw<'a>)
Represents an unparsed raw JSON value.
Array(Array<'a>)
Represents a JSON array.
Object(Object<'a>)
Represents a JSON object.
String(String<'a>)
Represents a JSON string.
Number(Number)
Represents a JSON number.
Boolean(bool)
Represents a JSON boolean.
Implementations§
Source§impl<'a> Value<'a>
impl<'a> Value<'a>
Sourcepub fn as_raw(&'a self) -> Option<Raw<'a>>
pub fn as_raw(&'a self) -> Option<Raw<'a>>
Returns unparsed raw JSON if it is still in raw form, None otherwise.
Sourcepub fn as_array(&mut self) -> Option<&mut Array<'a>>
pub fn as_array(&mut self) -> Option<&mut Array<'a>>
Returns a mutable reference to Array if it is an array, None otherwise.
Sourcepub fn into_array(self) -> Option<Array<'a>>
pub fn into_array(self) -> Option<Array<'a>>
Returns Array if it is an array, None otherwise.
Sourcepub fn as_object(&mut self) -> Option<&mut Object<'a>>
pub fn as_object(&mut self) -> Option<&mut Object<'a>>
Returns a mutable reference to Object if it is an object, None otherwise.
Sourcepub fn into_object(self) -> Option<Object<'a>>
pub fn into_object(self) -> Option<Object<'a>>
Returns Object if it is an object, None otherwise.
Sourcepub fn as_number(&mut self) -> Option<Number>
pub fn as_number(&mut self) -> Option<Number>
Returns Number if it is a number, None otherwise.
Sourcepub fn as_i64(&mut self) -> Option<i64>
pub fn as_i64(&mut self) -> Option<i64>
Returns i64 if it is an integer and negative, None otherwise.
Sourcepub fn as_u64(&mut self) -> Option<u64>
pub fn as_u64(&mut self) -> Option<u64>
Returns i64 if it is an integer and positive, None otherwise.
Sourcepub fn as_f64(&mut self) -> Option<f64>
pub fn as_f64(&mut self) -> Option<f64>
Returns f64 if it is a floating point number or an integer that is too big, None otherwise.
Sourcepub fn as_str(&mut self) -> Option<&str>
pub fn as_str(&mut self) -> Option<&str>
Returns string slice if it is a string, None otherwise.
Sourcepub fn pointer<P>(&'a self, p: P) -> Option<Value<'a>>
pub fn pointer<P>(&'a self, p: P) -> Option<Value<'a>>
Looks up a value by the given path.
This is faster than its mutating APIs if you only need to get a particular value once as it doesn’t cache the values. If the path is empty, then the root value is returned. The returned value will generally be a raw value unless it is a string in which case it will return a borrowed string. Numbers, booleans and nulls are returned as is.
§Example
use flexon::{LazyValue, jsonp};
let val: LazyValue = flexon::parse(r#"{"foo": ["bar", 123]}"#)?;
assert!(val.pointer(jsonp!["foo", 1]).unwrap().is_number());
assert!(val.pointer([0]).is_none());