merde_json

Struct JsonSerializer

source
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

source

pub fn from_vec(vec: Vec<u8>) -> Self

Uses the provided buffer as the target for serialization.

source

pub fn new() -> Self

Allocates a new buffer for serialization.

source

pub fn write_null(&mut self)

Writes the JSON null value.

source

pub fn write_bool(&mut self, value: bool)

Writes the JSON true or false value.

source

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.

source

pub fn write_f64(&mut self, value: f64)

Write a floating-point number as a JSON number.

source

pub fn write_str(&mut self, value: &str)

Write a string, with escaping.

source

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.

source

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.

source

pub fn into_inner(self) -> Vec<u8>

Get back the internal buffer

source

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?

Trait Implementations§

source§

impl Default for JsonSerializer

source§

fn default() -> JsonSerializer

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.