pub struct Serializer<'a, S: Schema> { /* private fields */ }Expand description
Serializes one resource’s records into JSON:API resource objects.
Borrows the schema rather than copying it, so your declaration stays the single source of truth.
Implementations§
Source§impl<'a, S: Schema> Serializer<'a, S>
impl<'a, S: Schema> Serializer<'a, S>
pub fn new(schema: &'a S) -> Self
Sourcepub fn record(&self, id: &str) -> Record<'a, S>
pub fn record(&self, id: &str) -> Record<'a, S>
Start building a resource object for id.
The usual entry point. Attributes and relationships are added
fluently, and the type, the self link and every relationship link
come from the schema:
serializer
.record(&id)
.attr("message", "buy milk")
.rel("owner", "u_01H8X")
.build()
```ignoreSourcepub fn record_owned(&self, id: String) -> Record<'a, S>
pub fn record_owned(&self, id: String) -> Record<'a, S>
Sourcepub fn serialize(
&self,
id: &str,
attributes: BTreeMap<String, Value>,
related: &BTreeMap<String, Vec<String>>,
) -> ResourceObject
pub fn serialize( &self, id: &str, attributes: BTreeMap<String, Value>, related: &BTreeMap<String, Vec<String>>, ) -> ResourceObject
Serialize a record from prepared maps.
attributes is the record’s data, already projected for any sparse
fieldset. related maps a relationship name to the ids on its far
side. Prefer Serializer::record unless the maps already exist —
this is the bulk path, for a listing built from a data layer.
Sourcepub fn relationship(
&self,
id: &str,
name: &str,
ids: &[String],
) -> Option<Relationship>
pub fn relationship( &self, id: &str, name: &str, ids: &[String], ) -> Option<Relationship>
Build one relationship’s linkage and links from the schema.
Returns None for a name the schema does not declare.