pub trait JSONWriter {
Show 15 methods
// Required methods
fn json_string(&mut self, value: &str);
fn json_string_part(&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_string(&mut self) { ... }
fn json_end_string(&mut self) { ... }
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§
Sourcefn json_string(&mut self, value: &str)
fn json_string(&mut self, value: &str)
Quotes and escapes the given string and writes the result to output with delimiting quotes.
Sourcefn json_string_part(&mut self, value: &str)
fn json_string_part(&mut self, value: &str)
Quotes and escapes the given string and writes the result to output without delimiting quotes.
Sourcefn json_fragment(&mut self, value: &str)
fn json_fragment(&mut self, value: &str)
write a raw json fragment
Provided Methods§
Sourcefn json_number_f64(&mut self, value: f64)
fn json_number_f64(&mut self, value: f64)
Converts number to string and writes it. Writes null for NaN and infinity
Sourcefn json_number_str(&mut self, value: &str)
fn json_number_str(&mut self, value: &str)
Writes a number that has already been converted to string
Sourcefn json_begin_object(&mut self)
fn json_begin_object(&mut self)
Called at the start of writing an object. Writes the opening bracket
Sourcefn json_end_object(&mut self, _empty: bool)
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.
Sourcefn json_begin_array(&mut self)
fn json_begin_array(&mut self)
Called at the start of writing an array.
Sourcefn json_end_array(&mut self, _empty: bool)
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.
Sourcefn json_begin_string(&mut self)
fn json_begin_string(&mut self)
Writes a double-quote.
Called when creating a JSONStringWriter
Sourcefn json_end_string(&mut self)
fn json_end_string(&mut self)
Writes a double-quote.
Called when dropping a JSONStringWriter
Sourcefn json_begin_array_value(&mut self, first: bool)
fn json_begin_array_value(&mut self, first: bool)
Called before each key-value pair in an object and each item in an array.
Sourcefn json_object_key(&mut self, key: &str, first: bool)
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
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl JSONWriter for String
impl JSONWriter for String
Source§fn json_begin_object(&mut self)
fn json_begin_object(&mut self)
Called at the start of writing an object.
Source§fn json_end_object(&mut self, _empty: bool)
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)
fn json_begin_array(&mut self)
Called at the start of writing an array.
Source§fn json_end_array(&mut self, _empty: bool)
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)
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)
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.