pub trait JsonBackend {
type Output;
// Required methods
fn begin_array(&mut self) -> Result<()>;
fn begin_object(&mut self) -> Result<()>;
fn end_array(&mut self) -> Result<()>;
fn end_object(&mut self) -> Result<()>;
fn finish(self) -> Result<Self::Output>;
fn write_bool(&mut self, b: bool) -> Result<()>;
fn write_name(&mut self, name: &str) -> Result<()>;
fn write_null(&mut self) -> Result<()>;
fn write_number(&mut self, n: u32) -> Result<()>;
fn write_string(&mut self, s: &str) -> Result<()>;
// Provided method
fn write_string_streaming<F>(&mut self, f: F) -> Result<()>
where F: FnOnce(&mut dyn Write) -> Result<()> { ... }
}Expand description
Low-level JSON token emitter. Implementations write JSON tokens to an
underlying sink. State validation is performed by crate::JsonEmitter,
not by the backend.
Required Associated Types§
Sourcetype Output
type Output
Type returned by JsonBackend::finish.
Required Methods§
Sourcefn begin_array(&mut self) -> Result<()>
fn begin_array(&mut self) -> Result<()>
Sourcefn begin_object(&mut self) -> Result<()>
fn begin_object(&mut self) -> Result<()>
Sourcefn end_array(&mut self) -> Result<()>
fn end_array(&mut self) -> Result<()>
End the current JSON array (writes ]).
§Errors
Returns any error produced by the underlying backend.
Sourcefn end_object(&mut self) -> Result<()>
fn end_object(&mut self) -> Result<()>
End the current JSON object (writes }).
§Errors
Returns any error produced by the underlying backend.
Sourcefn finish(self) -> Result<Self::Output>
fn finish(self) -> Result<Self::Output>
Finish writing and return the backend’s output.
§Errors
Returns any error produced by the underlying backend.
Sourcefn write_bool(&mut self, b: bool) -> Result<()>
fn write_bool(&mut self, b: bool) -> Result<()>
Sourcefn write_name(&mut self, name: &str) -> Result<()>
fn write_name(&mut self, name: &str) -> Result<()>
Sourcefn write_null(&mut self) -> Result<()>
fn write_null(&mut self) -> Result<()>
Sourcefn write_number(&mut self, n: u32) -> Result<()>
fn write_number(&mut self, n: u32) -> Result<()>
Provided Methods§
Sourcefn write_string_streaming<F>(&mut self, f: F) -> Result<()>
fn write_string_streaming<F>(&mut self, f: F) -> Result<()>
Write a string value by streaming bytes through a closure.
The default implementation buffers the bytes into a Vec<u8>, converts
to a &str, and delegates to write_string.
§Errors
Returns an error if the closure returns an I/O error, or if the buffered bytes are not valid UTF-8.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".