Struct nyoom_json::ArrayWriter

source ·
pub struct ArrayWriter<S: JsonBuffer> { /* private fields */ }
Expand description

Serializer for a JSON array.

Implementations§

source§

impl<S: JsonBuffer> ArrayWriter<S>

source

pub fn add(&mut self, val: impl WriteToJson<S>)

Adds a single primitive JSON value to this array.

Examples
let mut arr = ser.array();
arr.add("friends");
arr.add("romans");
arr.add("countrymen");
arr.end();
source

pub fn extend<V: WriteToJson<S>>(&mut self, vals: impl IntoIterator<Item = V>)

Adds a slice of a JSON primitive to this array.

Examples
let mut arr = ser.array();
arr.extend(&["friends", "romans", "countrymen"]);
arr.end();
source

pub fn add_complex<F>(&mut self, encoder: F)where F: FnOnce(SingleValueSerializer<&mut S>),

Adds an arbitrary JSON object to this array.

Arguments
  • encoder - A closure that encodes a single value into the array.
Examples
let mut arr = ser.array();
arr.add_complex(|mut ser| {
    let mut obj = ser.object();
    obj.field("kitten", true);
    obj.field("cuteness", 10.0);
});
arr.end();
source

pub fn add_object(&mut self) -> ObjectWriter<&mut S>

Adds a JSON object to this array.

Examples
let mut arr = ser.array();

let mut obj = arr.add_object();
obj.field("kitten", true);
obj.field("cuteness", 10.0);
obj.end();

arr.end();
source

pub fn add_array(&mut self) -> ArrayWriter<&mut S>

Adds a JSON array.. to this array.

Examples
let mut arr = ser.array();

let mut inner_arr = arr.add_array();
inner_arr.extend(&[1,2,3]);
inner_arr.end();

arr.end();
source

pub fn end(self)

Finishes out the array. Equivalent to drop(arr);

Trait Implementations§

source§

impl<S: JsonBuffer> Drop for ArrayWriter<S>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<S> RefUnwindSafe for ArrayWriter<S>where S: RefUnwindSafe,

§

impl<S> Send for ArrayWriter<S>where S: Send,

§

impl<S> Sync for ArrayWriter<S>where S: Sync,

§

impl<S> Unpin for ArrayWriter<S>where S: Unpin,

§

impl<S> UnwindSafe for ArrayWriter<S>where S: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.