Struct JSONObjectWriter

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

Helper for appending a JSON object 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> JSONObjectWriter<'_, W>

Source

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

Creates a new JSONObjectWriter that writes to the given buffer. Writes ‘{’ to the buffer immediately.

Source

pub fn object<'a>(&'a mut self, key: &str) -> JSONObjectWriter<'a, W>

Starts writing a nested object with given key:

Esacapes key, writes “"key":{” and returns a JSONObjectWriter

Source

pub fn array<'a>(&'a mut self, key: &str) -> JSONArrayWriter<'a, W>

Starts writing a nested array with given key:

Esacapes key, writes “"key":[” and returns a JSONArrayWriter.

Source

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

Escapes and appends key:value to the buffer

Source

pub fn string_writer(&mut self, key: &str) -> 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_key(&mut self, key: &str)

Writes a key without any value.

Consider using the methods value(key, value), object(key) and array(key) instead of using this method directly.

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 JSONObjectWriter<'_, 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<'a, W: JSONWriter> Drop for JSONObjectWriter<'a, W>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<'a, Writer = String> !UnwindSafe for JSONObjectWriter<'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.