Struct JSONArrayWriter

Source
pub struct JSONArrayWriter<'a, Writer: JSONWriter = String> {
    pub writer: &'a mut Writer,
    /* private fields */
}
Expand description

Helper for appending a JSON array to the borrowed buffer.

Appends ‘[’ on creation. Appends ‘]’ when dropped.

Fields§

§writer: &'a mut Writer

Mutable borrow of buffer

Consider using the methods instead of using this field directly. This field should not be used unless you know what you are doing.

Implementations§

Source§

impl<W: JSONWriter> JSONArrayWriter<'_, W>

Source

pub fn new(writer: &mut W) -> JSONArrayWriter<'_, W>

Creates a new JSONArrayWriter that writes to the given buffer. Writes ‘[’ to the buffer immediately.

Source

pub fn object(&mut self) -> JSONObjectWriter<'_, W>

Starts writing a nested object as array entry.

Writes ‘{’ and returns a JSONObjectWriter

Source

pub fn array(&mut self) -> JSONArrayWriter<'_, W>

Starts writing a nested array as array entry.

Writes ‘[’ and returns a JSONArrayWriter

Source

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

Writes given value as array entry

Source

pub fn string_writer(&mut self) -> JSONStringWriter<'_, W>

Write string with the given key, where the body of the string is built up using the JSONStringWriter that impls the fmt::Write trait and so can be used in the write! macro.

Source

pub fn write_comma(&mut self)

Writes a comma unless at the beginning of the array

Warning: If you use this method, you will have to write the value to the buffer yourself afterwards.

Source

pub fn end(self)

Drops the writer. Dropping causes ‘]’ to be appended to the buffer.

Source§

impl JSONArrayWriter<'_, String>

Source

pub fn output_buffered_data<Writer: Write>( &mut self, writer: &mut Writer, ) -> Result<usize, Error>

Writes the entire buffer to given writer and clears entire buffer on success.

Source

pub fn buffer_len(&self) -> usize

Returns buffer length in bytes

Trait Implementations§

Source§

impl<W: JSONWriter> Drop for JSONArrayWriter<'_, W>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, Writer> Freeze for JSONArrayWriter<'a, Writer>

§

impl<'a, Writer> RefUnwindSafe for JSONArrayWriter<'a, Writer>
where Writer: RefUnwindSafe,

§

impl<'a, Writer> Send for JSONArrayWriter<'a, Writer>
where Writer: Send,

§

impl<'a, Writer> Sync for JSONArrayWriter<'a, Writer>
where Writer: Sync,

§

impl<'a, Writer> Unpin for JSONArrayWriter<'a, Writer>

§

impl<'a, Writer = String> !UnwindSafe for JSONArrayWriter<'a, Writer>

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.