JsonArray

Struct JsonArray 

Source
pub struct JsonArray<Values> { /* private fields */ }
Expand description

JsonObject represents an RFC 8259 JSON Array. It wraps a mutable or immutable buffer of JSON values. The easiest way to use it is through the ArrayJsonArray type alias, however you can use JsonArray directly to wrap your own buffer like a heap allocated Vec.

Implementations§

Source§

impl<T> JsonArray<T>

Source

pub fn into_inner(self) -> (T, usize)

consume this JsonObject to return (field buffer, num fields considered initialized)

Source§

impl<'a, T: ValueBuffer<'a>> JsonArray<T>

Source

pub const fn wrap(values: T) -> Self

wrap a collection of values into a JsonArray and considers none of the values to be initialized

Source

pub fn wrap_init(values: T) -> Self

wrap a collection of fields into a JsonObject and considers all of the fields to be initialized

Source

pub const fn len(&self) -> usize

get the number of initialized values in this JsonArray. Same as self.values().len()

Source

pub fn capacity(&self) -> usize

get the max number of values this JsonArray can store

Source

pub fn values(&self) -> &[JsonValue<'a>]

get an immutable reference to the initialized values of this JsonArray

Source

pub fn serialize<Output: Write>( &self, output: Output, ) -> Result<usize, Output::Error>

attempt to serialize this JsonArray into the provided output & returns the number of bytes written on success

Source

pub fn serialize_resume<Output: Write>( &self, output: Output, resume_from: usize, ) -> Result<usize, (usize, Output::Error)>

attempt to serialize this JsonArray into the provided output starting from resume_from & returns the number of bytes written on both success & failure

Source§

impl<'a, T: ValueBufferMut<'a>> JsonArray<T>

Source

pub fn values_mut(&mut self) -> &mut [JsonValue<'a>]

get a mutable reference to the initialized fields of this JsonObject

Source

pub fn push<V: Into<JsonValue<'a>>>(&mut self, value: V) -> Result<(), ()>

attempt to push a new field - fails if there is not enough space

Source

pub fn pop(&mut self) -> Option<JsonValue<'a>>

attempt to pop an existing value - returns None if there are no initialized values

Source

pub fn parse( &mut self, data: &'a [u8], string_escape_buffer: &'a mut [u8], ) -> Result<usize, JsonParseFailure>

attempt to parse a JSON object from the provided data slice and write its fields into this JsonObject - returns a tuple of (num bytes consumed, num fields parsed) on success

Source§

impl<'a, const N: usize> JsonArray<[JsonValue<'a>; N]>

Source

pub const fn new() -> Self

convenience method to initialize a new array & call JsonObject::wrap on it

Source

pub const fn push_const(&mut self, value: JsonValue<'a>) -> Result<(), ()>

convenience method to automatically create an ArrayJsonObject if object parsing is successful similar to JsonObject::push but supports const contexts & only returns a reference

Source

pub const fn pop_const(&mut self) -> Option<&JsonValue<'a>>

similar to JsonObject::pop but supports const contexts

Source

pub const fn values_const(&self) -> &[JsonValue<'a>]

same as JsonObject::fields but supports const contexts

Source

pub const fn values_mut_const(&mut self) -> &mut [JsonValue<'a>]

same as JsonObject::fields_mut but supports const contexts

Trait Implementations§

Source§

impl<Values: Clone> Clone for JsonArray<Values>

Source§

fn clone(&self) -> JsonArray<Values>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Values: Debug> Debug for JsonArray<Values>

Source§

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

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

impl<'a, T: FieldBuffer<'a> + Default + ?Sized> Default for JsonArray<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a, T: ValueBuffer<'a>> Display for JsonArray<T>

Source§

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

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

impl<Values: Copy> Copy for JsonArray<Values>

Auto Trait Implementations§

§

impl<Values> Freeze for JsonArray<Values>
where Values: Freeze,

§

impl<Values> RefUnwindSafe for JsonArray<Values>
where Values: RefUnwindSafe,

§

impl<Values> Send for JsonArray<Values>
where Values: Send,

§

impl<Values> Sync for JsonArray<Values>
where Values: Sync,

§

impl<Values> Unpin for JsonArray<Values>
where Values: Unpin,

§

impl<Values> UnwindSafe for JsonArray<Values>
where Values: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.