Struct json_writer::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 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<'a>(writer: &'a mut W) -> JSONObjectWriter<'a, W>
pub fn new<'a>(writer: &'a mut W) -> JSONObjectWriter<'a, 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
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
Trait Implementations§
source§impl<'a, W: JSONWriter> Drop for JSONObjectWriter<'a, W>
impl<'a, W: JSONWriter> Drop for JSONObjectWriter<'a, W>
Auto Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more