Value

Struct Value 

Source
pub struct Value<'read, 'parent, R: Read<'read>, S: Stack> { /* private fields */ }
Expand description

A JSON value.

Implementations§

Source§

impl<'read, 'parent, R: Read<'read>, S: Stack> Value<'read, 'parent, R, S>

Source

pub fn kind(&mut self) -> Result<Type, JsonError<'read, R, S>>

Get the type of the current item.

This does not assert it’s a valid instance of this class of items. It solely asserts if this is a valid item, it will be of this type.

Source

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

Iterate over the fields within this object.

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

Source

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

Iterate over all items within this container.

Source

pub fn to_str( self, ) -> Result<impl use<'read, 'parent, R, S> + Iterator<Item = Result<char, JsonError<'read, R, S>>>, JsonError<'read, R, 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. If the underlying JSON is valid, the deserializer will remain usable afterwards however, even though the rest of the non-UTF-8 string will be inaccesible. Please keep this detail in mind.

Source

pub fn to_number(self) -> Result<Number, JsonError<'read, R, S>>

Get the current item as a number.

Source

pub fn to_bool(self) -> Result<bool, JsonError<'read, R, S>>

Get the current item as a bool.

Source

pub fn to_null(self) -> Result<(), JsonError<'read, R, S>>

Get the current item as null.

The point of this method is to assert the value is null and valid. kind only tells the caller if it’s a valid value, it will be null.

Trait Implementations§

Source§

impl<'read, 'parent, R: Read<'read>, S: Stack> Drop for Value<'read, 'parent, R, S>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'read, 'parent, R, S> Freeze for Value<'read, 'parent, R, S>

§

impl<'read, 'parent, R, S> RefUnwindSafe for Value<'read, 'parent, R, S>
where S: RefUnwindSafe, R: RefUnwindSafe, <R as Read<'read>>::Error: RefUnwindSafe, <S as Stack>::Error: RefUnwindSafe,

§

impl<'read, 'parent, R, S> Send for Value<'read, 'parent, R, S>
where S: Send, R: Send, <R as Read<'read>>::Error: Send, <S as Stack>::Error: Send,

§

impl<'read, 'parent, R, S> Sync for Value<'read, 'parent, R, S>
where S: Sync, R: Sync, <R as Read<'read>>::Error: Sync, <S as Stack>::Error: Sync,

§

impl<'read, 'parent, R, S> Unpin for Value<'read, 'parent, R, S>

§

impl<'read, 'parent, R, S> !UnwindSafe for Value<'read, 'parent, R, 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.