Skip to main content

Object

Struct Object 

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

A builder for one JSON object.

It writes the opening brace when the first field arrives, so an object that has no field is {} and not a broken one.

Implementations§

Source§

impl Object

Source

pub fn new(capacity: usize) -> Object

A new object, with room for fields of them.

Source

pub fn field<F>(&mut self, name: &str, value: F) -> &mut Object
where F: FnOnce(&mut String),

Write the name of a field and its value, which the caller writes.

The value is written by the closure into the same buffer, so a field that is an array or another object nests without a value tree in between.

Source

pub fn text(&mut self, name: &str, value: &str) -> &mut Object

Write a field whose value is a text.

Source

pub fn number(&mut self, name: &str, value: i64) -> &mut Object

Write a field whose value is a whole number.

Source

pub fn boolean(&mut self, name: &str, value: bool) -> &mut Object

Write a field whose value is a truth value.

Source

pub fn nothing(&mut self, name: &str) -> &mut Object

Write a field whose value is null.

Source

pub fn optional_number(&mut self, name: &str, value: Option<i64>) -> &mut Object

Write a field whose value is a whole number, or null when it is not there.

Source

pub fn texts(&mut self, name: &str, values: &[String]) -> &mut Object

Write a field whose value is an array of texts.

Source

pub fn finish(self) -> String

The object, as JSON.

Auto Trait Implementations§

§

impl Forget for Object

§

impl Freeze for Object

§

impl Move for Object

§

impl RefUnwindSafe for Object

§

impl Send for Object

§

impl Sync for Object

§

impl Unpin for Object

§

impl UnsafeUnpin for Object

§

impl UnwindSafe for Object

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.