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>
impl<'a, W: NonBlockingWrite, F: JsonFormatter, FF: FloatFormat> JsonWriter<'a, W, F, FF>
Sourcepub fn new(
inner: &'a mut W,
formatter: F,
float_format: FF,
) -> JsonWriter<'a, W, F, FF>
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.
Sourcepub async fn write_bytes(&mut self, data: &[u8]) -> Result<(), W::Error>
pub async fn write_bytes(&mut self, data: &[u8]) -> Result<(), W::Error>
Internal API for writing raw bytes to the underlying [Write].
Sourcepub async fn write_escaped_string(&mut self, s: &str) -> Result<(), W::Error>
pub async fn write_escaped_string(&mut self, s: &str) -> Result<(), W::Error>
Internal API for writing a string as an escaped JSON string.
Sourcepub async fn write_bool(&mut self, value: bool) -> Result<(), W::Error>
pub async fn write_bool(&mut self, value: bool) -> Result<(), W::Error>
Internal API for writing a bool.
Sourcepub async fn write_f64(&mut self, value: f64) -> Result<(), W::Error>
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.
Sourcepub async fn write_f32(&mut self, value: f32) -> Result<(), W::Error>
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.
Sourcepub async fn write_raw_num(
&mut self,
value: impl Display,
) -> Result<(), W::Error>
pub async fn write_raw_num( &mut self, value: impl Display, ) -> Result<(), W::Error>
internal API for writing raw int values
Sourcepub async fn write_format_after_key(&mut self) -> Result<(), W::Error>
pub async fn write_format_after_key(&mut self) -> Result<(), W::Error>
Internal API for interacting with the formatter
Sourcepub async fn write_format_after_start_nested(&mut self) -> Result<(), W::Error>
pub async fn write_format_after_start_nested(&mut self) -> Result<(), W::Error>
Internal API for interacting with the formatter
Sourcepub async fn write_format_after_element(&mut self) -> Result<(), W::Error>
pub async fn write_format_after_element(&mut self) -> Result<(), W::Error>
Internal API for interacting with the formatter
Sourcepub async fn write_format_before_end_nested(
&mut self,
is_empty: bool,
) -> Result<(), W::Error>
pub async fn write_format_before_end_nested( &mut self, is_empty: bool, ) -> Result<(), W::Error>
Internal API for interacting with the formatter
Sourcepub async fn write_format_indent(&mut self) -> Result<(), W::Error>
pub async fn write_format_indent(&mut self) -> Result<(), W::Error>
Internal API for interacting with the formatter
Sourcepub fn into_inner(self) -> Result<&'a mut W, W::Error>
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>
impl<'a, W: NonBlockingWrite> JsonWriter<'a, W, CompactFormatter, DefaultFloatFormat>
Sourcepub fn new_compact(inner: &'a mut W) -> Self
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>
impl<'a, W: NonBlockingWrite> JsonWriter<'a, W, PrettyFormatter, DefaultFloatFormat>
Sourcepub fn new_pretty(inner: &'a mut W) -> Self
pub fn new_pretty(inner: &'a mut W) -> Self
Convenience factory for creating a crate::blocking::JsonWriter with PrettyFormatter and DefaultFloatFormat