Skip to main content

ArrayBuilder

Struct ArrayBuilder 

Source
pub struct ArrayBuilder { /* private fields */ }
Expand description

Fluent builder for a JSON array ([...]).

Nested objects/arrays are written in place into the same buffer.

Implementations§

Source§

impl ArrayBuilder

Source

pub fn new() -> Self

Start an empty array.

Source

pub fn with_capacity(cap: usize) -> Self

Source

pub fn item(self, value: &(impl ToJsonBytes + ?Sized)) -> Self

Append a typed value.

Source

pub fn raw_item(self, raw_json: &[u8]) -> Self

Append already-encoded JSON value bytes.

Source

pub fn null_item(self) -> Self

Append JSON null.

Source

pub fn item_opt<T: ToJsonBytes + ?Sized>(self, value: Option<&T>) -> Self

Append value when Some.

Source

pub fn object(self, build: impl FnOnce(ObjectBuilder) -> ObjectBuilder) -> Self

Nested object element written in place.

Source

pub fn array(self, build: impl FnOnce(ArrayBuilder) -> ArrayBuilder) -> Self

Nested array element written in place.

Source

pub fn extend<I, T>(self, iter: I) -> Self
where I: IntoIterator<Item = T>, T: ToJsonBytes,

Append all items from an iterator.

Source

pub fn finish(self) -> Vec<u8> ⓘ

Finish and return compact JSON bytes.

Source

pub fn finish_into(self, out: &mut Vec<u8>)

Append the finished array onto out.

Source

pub fn into_doc(self) -> TypedDoc

Finish into a TypedDoc.

Source

pub fn len(&self) -> usize

Trait Implementations§

Source§

impl Clone for ArrayBuilder

Source§

fn clone(&self) -> ArrayBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ArrayBuilder

Source§

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

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

impl Default for ArrayBuilder

Source§

fn default() -> Self

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

impl ToJsonBytes for ArrayBuilder

Source§

fn to_json_bytes(&self) -> Vec<u8> ⓘ

Serializes the value into a raw JSON byte vector. Read more
Source§

fn write_json_bytes(&self, out: &mut Vec<u8>)

Append the JSON encoding of self into out (avoids an intermediate Vec when the implementor overrides this; default uses to_json_bytes).

Auto Trait Implementations§

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, 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.