pub struct JsonSerializer { /* private fields */ }Expand description
Writes JSON to a Vec<u8>. None of its methods can fail, since it doesn’t target
an io::Write. You can provide your own buffer via JsonSerializer::from_vec.
When you’re done with the serializer, you can call JsonSerializer::into_inner to
get the buffer back.
Implementations§
source§impl JsonSerializer
impl JsonSerializer
sourcepub fn from_vec(vec: Vec<u8>) -> Self
pub fn from_vec(vec: Vec<u8>) -> Self
Uses the provided buffer as the target for serialization.
sourcepub fn write_null(&mut self)
pub fn write_null(&mut self)
Writes the JSON null value.
sourcepub fn write_bool(&mut self, value: bool)
pub fn write_bool(&mut self, value: bool)
Writes the JSON true or false value.
sourcepub fn write_i64(&mut self, value: i64)
pub fn write_i64(&mut self, value: i64)
Write a number as a JSON number. Numbers bigger than 2**53 might not be parsed correctly by other implementations.
sourcepub fn write_obj(&mut self) -> ObjectGuard<'_>
pub fn write_obj(&mut self) -> ObjectGuard<'_>
This writes the opening brace of an object, and gives you a guard object to write the key-value pairs. When the guard is dropped, the closing brace is written.
sourcepub fn write_arr(&mut self) -> ArrayGuard<'_>
pub fn write_arr(&mut self) -> ArrayGuard<'_>
This writes the opening bracket of an array, and gives you a guard object to write the elements. When the guard is dropped, the closing bracket is written.
sourcepub fn into_inner(self) -> Vec<u8> ⓘ
pub fn into_inner(self) -> Vec<u8> ⓘ
Get back the internal buffer
sourcepub fn as_mut_vec(&mut self) -> &mut Vec<u8> ⓘ
pub fn as_mut_vec(&mut self) -> &mut Vec<u8> ⓘ
Mutably borrow the internal buffer (as a Vec<u8> so it’s growable).
This is particularly useful when you want to use an interface like format_into that expects a dyn Writer?