pub trait ApiBody {
fn api_body_info() -> ApiBodyInfo;
fn to_json_vec(&self) -> Vec<u8> ⓘ
where
Self: Serialize,
{ ... }
fn to_json_value(&self) -> Value
where
Self: Serialize,
{ ... }
fn from_json_slice(bytes: &[u8]) -> Result<Self>
where
Self: DeserializeOwned,
{ ... }
fn from_json_value(value: Value) -> Result<Self>
where
Self: DeserializeOwned,
{ ... }
}
Expand description
Any type that implements this trait can be described in terms of ApiBodyInfo
, and
can potentially also be serialized or deserizlied from JSON.
This type should not be manually implemented in most cases; instead the ApiBody
macro should be relied on to ensure that the description and shape of the type are consistent with how
it will be serialized.
In some cases however, it is necessary to manually implement this for a type (for example, an external type).
Required Methods§
sourcefn api_body_info() -> ApiBodyInfo
fn api_body_info() -> ApiBodyInfo
This returns information about the shape of the type and description of parts of it.
Provided Methods§
sourcefn to_json_value(&self) -> Valuewhere
Self: Serialize,
fn to_json_value(&self) -> Valuewhere
Self: Serialize,
Serialize the type to a serde_json::Value
.
sourcefn from_json_slice(bytes: &[u8]) -> Result<Self>where
Self: DeserializeOwned,
fn from_json_slice(bytes: &[u8]) -> Result<Self>where
Self: DeserializeOwned,
Deserialize from bytes containing a JSON value.
sourcefn from_json_value(value: Value) -> Result<Self>where
Self: DeserializeOwned,
fn from_json_value(value: Value) -> Result<Self>where
Self: DeserializeOwned,
Deserialize from a serde_json::Value
.