jsonway::array_builder

Struct ArrayBuilder

Source
pub struct ArrayBuilder {
    pub array: JsonArray,
    pub null: bool,
    pub skip: bool,
    pub root: Option<String>,
}

Fields§

§array: JsonArray§null: bool§skip: bool§root: Option<String>

Implementations§

Source§

impl ArrayBuilder

Use ArrayBuilder to produce JSON arrays

Source

pub fn new() -> ArrayBuilder

Source

pub fn from_json(array: Value) -> Option<ArrayBuilder>

Initialize builder with initial value.

Source

pub fn build<F>(builder: F) -> ArrayBuilder
where F: FnOnce(&mut ArrayBuilder),

Create new ArrayBuilder, pass it to closure as mutable ref and return.

Source

pub fn push_json(&mut self, value: Value)

Push JSON value to array.

Source

pub fn array<F>(&mut self, builder: F)
where F: FnOnce(&mut ArrayBuilder),

Create new array and push it.

Source

pub fn object<F>(&mut self, builder: F)
where F: FnOnce(&mut ObjectBuilder),

Create new object and push it

Source

pub fn null(&mut self)

It you call null, this array will be converted to null when converting to raw JSON value.

Source

pub fn skip(&mut self)

It you call skip, this array will be skipped.

Source

pub fn root(&mut self, root: &str)

Source

pub fn has_root(&mut self) -> bool

Source

pub fn unwrap(self) -> Value

Move out internal JSON value.

Source§

impl ArrayBuilder

Source

pub fn push<T: Serialize>(&mut self, value: T)

Push to array something that can be converted to JSON.

Source§

impl ArrayBuilder

Source

pub fn objects<A, T: Iterator<Item = A>, F>(&mut self, iter: T, func: F)
where F: Fn(A, &mut ObjectBuilder),

Fill this array by objects builded from iterator.

Source

pub fn arrays<A, T: Iterator<Item = A>, F>(&mut self, iter: T, func: F)
where F: Fn(A, &mut ArrayBuilder),

Source

pub fn map<A, T: Iterator<Item = A>, F>(&mut self, iter: T, func: F)
where F: Fn(A) -> Value,

Fill this array by JSON values builded from iterator.

Trait Implementations§

Source§

impl Serialize for ArrayBuilder

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Copy self to new JSON instance.

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