Struct json_writer::JSONObjectWriter
source · pub struct JSONObjectWriter<'a> {
pub buffer: &'a mut String,
/* private fields */
}Expand description
Helper for appending a JSON object to the borrowed buffer.
Appends ‘{’ on creation. Appends ‘}’ when dropped.
Fields§
§buffer: &'a mut StringMutable 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 JSONObjectWriter<'_>
impl JSONObjectWriter<'_>
sourcepub fn new<'a>(buffer: &'a mut String) -> JSONObjectWriter<'a>
pub fn new<'a>(buffer: &'a mut String) -> JSONObjectWriter<'a>
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>
pub fn object<'a>(&'a mut self, key: &str) -> JSONObjectWriter<'a>
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>
pub fn array<'a>(&'a mut self, key: &str) -> JSONArrayWriter<'a>
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 write_key(&mut self, key: &str)
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 youself afterwards.
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