jsonway::object_builder

Struct ObjectBuilder

Source
pub struct ObjectBuilder {
    pub object: Object,
    pub null: bool,
    pub skip: bool,
    pub root: Option<String>,
}

Fields§

§object: Object§null: bool§skip: bool§root: Option<String>

Implementations§

Source§

impl ObjectBuilder

ObjectBuilder is used to produce JSON objects

Source

pub fn new() -> ObjectBuilder

Source

pub fn from_json(object: Value) -> Option<ObjectBuilder>

Initialize builder with initial value.

Source

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

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

Source

pub fn null(&mut self)

It you call null, this object will be converted to null.

Source

pub fn skip(&mut self)

It you call skip, this object 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 ObjectBuilder

Source

pub fn set<V: Serialize, N: Into<String>>(&mut self, name: N, value: V)

Set object’s name field with something that can be converted to Value value.

Source

pub fn call<V: Serialize, N: Into<String>>(&mut self, name: N, value: V)

Stub for future use

Source§

impl ObjectBuilder

Source

pub fn set_json<N: Into<String>>(&mut self, name: N, value: Value)

Set object’s name field with raw Value value.

Source

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

Build new array and set object’s name field with it.

Source

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

Build new object and set object’s name field with it.

Trait Implementations§

Source§

impl Serialize for ObjectBuilder

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.