JsonObject

Struct JsonObject 

Source
pub struct JsonObject<Fields> { /* private fields */ }
Expand description

a JSON Object (rfc8259) that wraps a mutable or immutable buffer of object fields. The easiest way to use it is through the ArrayJsonObject type alias, however you can use JsonObject directly to wrap your own buffer like a heap allocated Vec

Implementations§

Source§

impl<T> JsonObject<T>

Source

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

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

Source§

impl<'a, T: FieldBuffer<'a>> JsonObject<T>

(re-export from embedded-io-adapters)

Source

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

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

Source

pub fn wrap_init(fields: 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 fields in this JsonObject. Same as self.fields().len().

Source

pub fn capacity(&self) -> usize

get the max number of fields this JsonObject can store.

Source

pub fn fields(&self) -> &[JsonField<'a, 'a>]

get an immutable reference to the initialized fields of this JsonObject

Source

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

attempt to serialize this JsonObject into the provided output, returns the number of bytes written on success

Source§

impl<'a, T: FieldBufferMut<'a>> JsonObject<T>

Source

pub fn fields_mut(&mut self) -> &mut [JsonField<'a, 'a>]

get a mutable reference to the initialized fields of this JsonObject

Source

pub fn push<'x: 'a, 'y: 'a>( &mut self, field: JsonField<'x, 'y>, ) -> Result<(), JsonField<'x, 'y>>

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

Source

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

attempt to pop an existing field - returns None if there are no initialized fields

Source

pub fn push_field<'x: 'a, 'y: 'a>( &mut self, key: &'x str, value: JsonValue<'y>, ) -> Result<(), ()>

convenience helper to create and push a new field

Source

pub fn parse( &mut self, data: &'a [u8], ) -> Result<(usize, 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, T: FieldBufferMut<'a> + Default> JsonObject<T>

Source

pub fn default_parsed(data: &'a [u8]) -> Result<(usize, Self), JsonParseFailure>

convenience method to automatically create an JsonObject if object parsing is successful

Source§

impl<'a, const N: usize> JsonObject<[JsonField<'a, 'a>; N]>

Source

pub const fn new() -> Self

convenience method to call JsonObject::wrap on a new array

Source

pub fn new_parsed(data: &'a [u8]) -> Result<(usize, Self), JsonParseFailure>

convenience method to automatically create an ArrayJsonObject if object parsing is successful

Source

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

similar to JsonObject::push but supports const contexts & only returns a reference

Source

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

similar to JsonObject::pop but supports const contexts

Source

pub const fn fields_const(&self) -> &[JsonField<'a, 'a>]

same as JsonObject::fields but supports const contexts

Source

pub const fn fields_mut_const(&mut self) -> &mut [JsonField<'a, 'a>]

same as JsonObject::fields_mut but supports const contexts

Trait Implementations§

Source§

impl<Fields: Debug> Debug for JsonObject<Fields>

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 JsonObject<T>

Source§

fn default() -> Self

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

impl<'a, T: FieldBuffer<'a>> From<T> for JsonObject<T>

Source§

fn from(field_buffer: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<Fields> Freeze for JsonObject<Fields>
where Fields: Freeze,

§

impl<Fields> RefUnwindSafe for JsonObject<Fields>
where Fields: RefUnwindSafe,

§

impl<Fields> Send for JsonObject<Fields>
where Fields: Send,

§

impl<Fields> Sync for JsonObject<Fields>
where Fields: Sync,

§

impl<Fields> Unpin for JsonObject<Fields>
where Fields: Unpin,

§

impl<Fields> UnwindSafe for JsonObject<Fields>
where Fields: 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> 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.