Skip to main content

LazyValue

Enum LazyValue 

Source
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>

Source

pub fn as_raw(&'a self) -> Option<Raw<'a>>

Returns unparsed raw JSON if it is still in raw form, None otherwise.

Source

pub fn as_null(&mut self) -> Option<()>

Returns () if it is a null, None otherwise.

Source

pub fn as_bool(&mut self) -> Option<bool>

Returns bool if it is a boolean, None otherwise.

Source

pub fn as_array(&mut self) -> Option<&mut Array<'a>>

Returns a mutable reference to Array if it is an array, None otherwise.

Source

pub fn into_array(self) -> Option<Array<'a>>

Returns Array if it is an array, None otherwise.

Source

pub fn as_object(&mut self) -> Option<&mut Object<'a>>

Returns a mutable reference to Object if it is an object, None otherwise.

Source

pub fn into_object(self) -> Option<Object<'a>>

Returns Object if it is an object, None otherwise.

Source

pub fn as_number(&mut self) -> Option<Number>

Returns Number if it is a number, None otherwise.

Source

pub fn as_i64(&mut self) -> Option<i64>

Returns i64 if it is an integer and negative, None otherwise.

Source

pub fn as_u64(&mut self) -> Option<u64>

Returns i64 if it is an integer and positive, None otherwise.

Source

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.

Source

pub fn as_str(&mut self) -> Option<&str>

Returns string slice if it is a string, None otherwise.

Source

pub fn is_raw(&self) -> bool

Returns true if it is still a raw value, false otherwise.

Source

pub fn is_str(&self) -> bool

Returns true if it is a string, false otherwise.

Source

pub fn is_null(&self) -> bool

Returns true if it is a null, false otherwise.

Source

pub fn is_bool(&self) -> bool

Returns true if it is a boolean, false otherwise.

Source

pub fn is_array(&self) -> bool

Returns true if it is an array, false otherwise.

Source

pub fn is_object(&self) -> bool

Returns true if it is an object, false otherwise.

Source

pub fn is_number(&self) -> bool

Returns true if it is a number, false otherwise.

Source

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());

Trait Implementations§

Source§

impl Debug for Value<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Index<&str> for Value<'a>

Source§

type Output = Value<'a>

The returned type after indexing.
Source§

fn index(&self, _: &str) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a> Index<usize> for Value<'a>

Source§

type Output = Value<'a>

The returned type after indexing.
Source§

fn index(&self, _: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a> IndexMut<&str> for Value<'a>

Source§

fn index_mut(&mut self, key: &str) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a> IndexMut<usize> for Value<'a>

Source§

fn index_mut(&mut self, idx: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, S: Source<Volatility = NonVolatile>> ValueBuilder<'a, S> for Value<'a>

Source§

const LAZY: bool = true

Whether the value that it is building is lazy. Read more
Source§

const CUSTOM_LITERAL: bool = false

Whether the value is to parse literals by itself. Read more
Source§

type Error = Error

The error type used by this builder.
Source§

type Array = _Array

The array type used by this builder.
Source§

type Object = _Object<'a, S, Value<'a>>

The object type used by this builder.
Source§

type String = _String

The string type used by this builder.
Source§

fn literal(_: &[u8]) -> Result<Self, Self::Error>

Creates a value by the given byte slice. Read more
Source§

fn integer(_: u64, _: bool) -> Self

Creates a value by the given integer value.
Source§

fn float(_: f64) -> Self

Creates a value by the given floating point value.
Source§

fn bool(_: bool) -> Self

Creates a value by the given boolean value.
Source§

fn null() -> Self

Creates a value in the context of null value in JSON.
Source§

fn raw(s: &'a [u8]) -> Self

Creates a value by the given raw JSON byte slice. Read more
Source§

fn apply_span(&mut self, _: usize, _: usize)

Applies span information. The given offsets will be byte offsets.

Auto Trait Implementations§

§

impl<'a> Freeze for Value<'a>

§

impl<'a> RefUnwindSafe for Value<'a>

§

impl<'a> !Send for Value<'a>

§

impl<'a> !Sync for Value<'a>

§

impl<'a> Unpin for Value<'a>

§

impl<'a> UnwindSafe for Value<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.