Trait JsonApiModel

Source
pub trait JsonApiModel: Serialize
where for<'de> Self: Deserialize<'de>,
{ // Provided methods fn from_jsonapi_resource( resource: &Resource, included: &Option<Resources>, ) -> Result<Self> { ... } fn from_jsonapi_document(doc: &DocumentData) -> Result<Self> { ... } fn to_jsonapi_resource(&self) -> (Resource, Option<Resources>) { ... } fn to_jsonapi_document(&self) -> JsonApiDocument { ... } }
Expand description

A trait for any struct that can be converted from/into a Resource. The only requirement is that your struct has an id: String field. You shouldn’t be implementing JsonApiModel manually, look at the jsonapi_model! macro instead.

Provided Methods§

Source

fn from_jsonapi_resource( resource: &Resource, included: &Option<Resources>, ) -> Result<Self>

Source

fn from_jsonapi_document(doc: &DocumentData) -> Result<Self>

Create a single resource object or collection of resource objects directly from DocumentData. This method will parse the document (the data and included resources) in an attempt to instantiate the calling struct.

Source

fn to_jsonapi_resource(&self) -> (Resource, Option<Resources>)

Converts the instance of the struct into a Resource

Source

fn to_jsonapi_document(&self) -> JsonApiDocument

Converts the struct into a complete JsonApiDocument

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.

Implementations on Foreign Types§

Source§

impl<M: JsonApiModel> JsonApiModel for Box<M>

Implementors§