pub trait JSONWriter {
    // Required methods
    fn json_string(&mut self, value: &str);
    fn json_fragment(&mut self, value: &str);

    // Provided methods
    fn json_null(&mut self) { ... }
    fn json_bool(&mut self, value: bool) { ... }
    fn json_number_f64(&mut self, value: f64) { ... }
    fn json_number_str(&mut self, value: &str) { ... }
    fn json_begin_object(&mut self) { ... }
    fn json_end_object(&mut self, _empty: bool) { ... }
    fn json_begin_array(&mut self) { ... }
    fn json_end_array(&mut self, _empty: bool) { ... }
    fn json_begin_array_value(&mut self, first: bool) { ... }
    fn json_object_key(&mut self, key: &str, first: bool) { ... }
}
Expand description

Writer trait for custom formatting and output

You most likely want to use JSONObjectWriter or JSONArrayWriter instead of using this directly

Required Methods§

source

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

Quotes and escapes the given string and writes the result to output

source

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

write a raw json fragment

Provided Methods§

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_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.

empty is true when the object contains no key-value pairs.

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.

empty is true when the array contains no items.

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

Implementations on Foreign Types§

source§

impl JSONWriter for String

source§

fn json_begin_object(&mut self)

Called at the start of writing an object.

source§

fn json_end_object(&mut self, _empty: bool)

Called after writing all key-value pairs of an object.

empty is true when the object contains no key-value pairs.

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.

empty is true when the array contains no items.

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)

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

source§

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

source§

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

Implementors§