pub trait ToJson: Sized + Serialize {
// Provided methods
fn to_json(&self) -> Result<String, Error> { ... }
fn to_json_vec(&self) -> Result<Vec<u8>, Error> { ... }
fn to_json_value(&self) -> Result<Value, Error> { ... }
fn to_json_pretty(&self) -> Result<String, Error> { ... }
}
Expand description
A convenience-trait for types that can be serialized as JSON.
Provided Methods§
Sourcefn to_json_value(&self) -> Result<Value, Error>
fn to_json_value(&self) -> Result<Value, Error>
Serialize self
as a serde_json::Value
.
Sourcefn to_json_pretty(&self) -> Result<String, Error>
fn to_json_pretty(&self) -> Result<String, Error>
Serialize self
as a pretty-printed string of JSON.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.