Struct PrettyJSONWriter

Source
pub struct PrettyJSONWriter<'a> {
    pub buffer: &'a mut String,
    /* private fields */
}
Expand description

Formats JSON in a human-readable format with whitespace, newlines, and indentation.

Fields§

§buffer: &'a mut String

Result

Implementations§

Source§

impl PrettyJSONWriter<'_>

Source

pub fn new(buffer: &mut String) -> PrettyJSONWriter<'_>

Creates a new human-readable formatter with two spaces for indentation.

Source

pub fn with_indent<'a>( buffer: &'a mut String, indent: &'a str, ) -> PrettyJSONWriter<'a>

Creates a new formatter using indent for indentation.

Trait Implementations§

Source§

impl JSONWriter for PrettyJSONWriter<'_>

Source§

fn json_begin_object(&mut self)

Called at the start of writing an object. Writes the opening bracket
Source§

fn json_end_object(&mut self, empty: bool)

Called after writing all key-value pairs of an object. Read more
Source§

fn json_begin_array(&mut self)

Called at the start of writing an array.
Source§

fn json_end_array(&mut self, empty: bool)

Called after writing all items of an array. Read more
Source§

fn json_begin_array_value(&mut self, first: bool)

Called before each key-value pair in an object and each item in an array.
Source§

fn json_object_key(&mut self, key: &str, first: bool)

writes a comma when not first entry, escapes and writes the key and a colon
Source§

fn json_string(&mut self, value: &str)

Quotes and escapes the given string and writes the result to output with delimiting quotes.
Source§

fn json_string_part(&mut self, value: &str)

Quotes and escapes the given string and writes the result to output without delimiting quotes.
Source§

fn json_fragment(&mut self, value: &str)

write a raw json fragment
Source§

fn json_null(&mut self)

Writes null
Source§

fn json_bool(&mut self, value: bool)

Writes true or false
Source§

fn json_number_f64(&mut self, value: f64)

Converts number to string and writes it. Writes null for NaN and infinity
Source§

fn json_number_str(&mut self, value: &str)

Writes a number that has already been converted to string
Source§

fn json_begin_string(&mut self)

Writes a double-quote. Read more
Source§

fn json_end_string(&mut self)

Writes a double-quote. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for PrettyJSONWriter<'a>

§

impl<'a> RefUnwindSafe for PrettyJSONWriter<'a>

§

impl<'a> Send for PrettyJSONWriter<'a>

§

impl<'a> Sync for PrettyJSONWriter<'a>

§

impl<'a> Unpin for PrettyJSONWriter<'a>

§

impl<'a> !UnwindSafe for PrettyJSONWriter<'a>

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.