Value

Struct Value 

Source
pub struct Value<'bytes, 'parent, B: BytesLike<'bytes>, S: Stack> { /* private fields */ }
Expand description

A JSON value.

Implementations§

Source§

impl<'bytes, 'parent, B: BytesLike<'bytes>, S: Stack> Value<'bytes, 'parent, B, S>

Source

pub fn is_object(&self) -> Result<bool, JsonError<'bytes, B, S>>

Check if the current item is an object.

Source

pub fn fields( self, ) -> Result<FieldIterator<'bytes, 'parent, B, S>, JsonError<'bytes, B, S>>

Iterate over the fields within this object.

If a field is present multiple times, this will yield each instance.

Source

pub fn is_array(&self) -> Result<bool, JsonError<'bytes, B, S>>

Check if the current item is an array.

Source

pub fn iterate( self, ) -> Result<ArrayIterator<'bytes, 'parent, B, S>, JsonError<'bytes, B, S>>

Iterate over all items within this container.

Source

pub fn is_str(&self) -> Result<bool, JsonError<'bytes, B, S>>

Check if the current item is a string.

Source

pub fn to_str( self, ) -> Result<impl use<'bytes, B, S> + Iterator<Item = Result<char, JsonError<'bytes, B, S>>>, JsonError<'bytes, B, S>>

Get the current item as a ‘string’.

As we cannot perform allocations, we do not yield a alloc::string::String but rather an iterator for the contents of the serialized string (with its escape sequences handled). This may be converted to an String with .collect::<Result<String, _>>()?.

RFC 8259 allows strings to specify invalid UTF-8 codepoints. This library supports working with such values, as required to be compliant with RFC 8259, but this function’s return value will error when attempting to return a non-UTF-8 value. Please keep this subtlety in mind.

Source

pub fn as_i64(&self) -> Result<i64, JsonError<'bytes, B, S>>

Get the current item as an i64.

This uses the definition of a number defined in RFC 8259, then constrains it to having no fractional, exponent parts. Then, it’s yielded if it’s representable within an i64.

This is exact. It does not go through f64 and does not experience its approximations.

Source

pub fn as_f64(&self) -> Result<f64, JsonError<'bytes, B, S>>

Get the current item as an f64.

Source

pub fn as_bool(&self) -> Result<bool, JsonError<'bytes, B, S>>

Get the current item as a bool.

Source

pub fn is_null(&self) -> Result<bool, JsonError<'bytes, B, S>>

Check if the current item is null.

Trait Implementations§

Source§

impl<'bytes, 'parent, B: BytesLike<'bytes>, S: Stack> Drop for Value<'bytes, 'parent, B, S>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'bytes, 'parent, B, S> Freeze for Value<'bytes, 'parent, B, S>

§

impl<'bytes, 'parent, B, S> RefUnwindSafe for Value<'bytes, 'parent, B, S>

§

impl<'bytes, 'parent, B, S> Send for Value<'bytes, 'parent, B, S>
where B: Send, S: Send, <B as BytesLike<'bytes>>::Error: Send, <S as Stack>::Error: Send,

§

impl<'bytes, 'parent, B, S> Sync for Value<'bytes, 'parent, B, S>
where B: Sync, S: Sync, <B as BytesLike<'bytes>>::Error: Sync, <S as Stack>::Error: Sync,

§

impl<'bytes, 'parent, B, S> Unpin for Value<'bytes, 'parent, B, S>

§

impl<'bytes, 'parent, B, S> !UnwindSafe for Value<'bytes, 'parent, B, S>

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.