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 WriterMutable 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>
impl<W: JSONWriter> JSONObjectWriter<'_, W>
Sourcepub fn new(writer: &mut W) -> JSONObjectWriter<'_, W>
pub fn new(writer: &mut W) -> JSONObjectWriter<'_, W>
Creates a new JSONObjectWriter that writes to the given buffer. Writes ‘{’ to the buffer immediately.
Sourcepub fn object<'a>(&'a mut self, key: &str) -> JSONObjectWriter<'a, W>
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
Sourcepub fn array<'a>(&'a mut self, key: &str) -> JSONArrayWriter<'a, W>
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.
Sourcepub fn value<T: JSONWriterValue>(&mut self, key: &str, value: T)
pub fn value<T: JSONWriterValue>(&mut self, key: &str, value: T)
Escapes and appends key:value to the buffer
Sourcepub fn string_writer(&mut self, key: &str) -> JSONStringWriter<'_, W>
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§impl JSONObjectWriter<'_, String>
impl JSONObjectWriter<'_, String>
Sourcepub fn output_buffered_data<Writer: Write>(
&mut self,
writer: &mut Writer,
) -> Result<usize, Error>
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.
Sourcepub fn buffer_len(&self) -> usize
pub fn buffer_len(&self) -> usize
Returns buffer length in bytes