JsonWriter

Struct JsonWriter 

Source
pub struct JsonWriter<'a, W: NonBlockingWrite, F: JsonFormatter, FF: FloatFormat> { /* private fields */ }
Expand description

JsonWriter is the starting point for serializing JSON with this library. It is a thin wrapper around a [Write], adding some JSON specifics and also formatting.

Application code should usually not have to interact with JsonWriter directly, but through [ObjectSer] or [ArraySer] wrapped around it.

Implementations§

Source§

impl<'a, W: NonBlockingWrite, F: JsonFormatter, FF: FloatFormat> JsonWriter<'a, W, F, FF>

Source

pub fn new( inner: &'a mut W, formatter: F, float_format: FF, ) -> JsonWriter<'a, W, F, FF>

Create a new JsonWriter instance for given [Write] instance and an explicitly provided JsonFormatter. It gives full flexibility; for most cases, new_compact() and new_pretty() functions are more convenient.

Source

pub async fn write_bytes(&mut self, data: &[u8]) -> Result<(), W::Error>

Internal API for writing raw bytes to the underlying [Write].

Source

pub async fn write_escaped_string(&mut self, s: &str) -> Result<(), W::Error>

Internal API for writing a string as an escaped JSON string.

Source

pub async fn write_bool(&mut self, value: bool) -> Result<(), W::Error>

Internal API for writing a bool.

Source

pub async fn write_f64(&mut self, value: f64) -> Result<(), W::Error>

Internal API for writing a floating point number, representing non-finite numbers as null.

Source

pub async fn write_f32(&mut self, value: f32) -> Result<(), W::Error>

Internal API for writing a floating point number, representing non-finite numbers as null.

Source

pub async fn write_raw_num( &mut self, value: impl Display, ) -> Result<(), W::Error>

internal API for writing raw int values

Source

pub async fn write_format_after_key(&mut self) -> Result<(), W::Error>

Internal API for interacting with the formatter

Source

pub async fn write_format_after_start_nested(&mut self) -> Result<(), W::Error>

Internal API for interacting with the formatter

Source

pub async fn write_format_after_element(&mut self) -> Result<(), W::Error>

Internal API for interacting with the formatter

Source

pub async fn write_format_before_end_nested( &mut self, is_empty: bool, ) -> Result<(), W::Error>

Internal API for interacting with the formatter

Source

pub async fn write_format_indent(&mut self) -> Result<(), W::Error>

Internal API for interacting with the formatter

Source

pub fn into_inner(self) -> Result<&'a mut W, W::Error>

End this JsonWriter’s lifetime, returning the [Write] instance it owned. This function returns any unreported errors.

Source§

impl<'a, W: NonBlockingWrite> JsonWriter<'a, W, CompactFormatter, DefaultFloatFormat>

Source

pub fn new_compact(inner: &'a mut W) -> Self

Convenience factory for creating a crate::blocking::JsonWriter with CompactFormatter and DefaultFloatFormat

Source§

impl<'a, W: NonBlockingWrite> JsonWriter<'a, W, PrettyFormatter, DefaultFloatFormat>

Source

pub fn new_pretty(inner: &'a mut W) -> Self

Convenience factory for creating a crate::blocking::JsonWriter with PrettyFormatter and DefaultFloatFormat

Auto Trait Implementations§

§

impl<'a, W, F, FF> Freeze for JsonWriter<'a, W, F, FF>
where F: Freeze, FF: Freeze,

§

impl<'a, W, F, FF> RefUnwindSafe for JsonWriter<'a, W, F, FF>

§

impl<'a, W, F, FF> Send for JsonWriter<'a, W, F, FF>
where F: Send, FF: Send, W: Send,

§

impl<'a, W, F, FF> Sync for JsonWriter<'a, W, F, FF>
where F: Sync, FF: Sync, W: Sync,

§

impl<'a, W, F, FF> Unpin for JsonWriter<'a, W, F, FF>
where F: Unpin, FF: Unpin,

§

impl<'a, W, F, FF> !UnwindSafe for JsonWriter<'a, W, F, FF>

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.