Expand description
Your data + your schema → ResourceObject.
Describe a resource once by implementing Schema and
RelationshipDef, and this module writes the JSON:API envelope for it:
the type/id wrapper, relationship linkage, and self/related links.
Nothing here needs a particular ORM or data layer — a Schema is three
methods over whatever types you already have.
ⓘ
struct Todo;
impl Schema for Todo {
type Relationship = Rel;
fn name(&self) -> &str { "todo" }
fn base_path(&self) -> &str { "/todos" }
fn relationships(&self) -> &[Rel] { &[Rel::to_one("owner", "user")] }
}
let object = Serializer::new(&Todo)
.record("t_1")
.attr("message", "buy milk")
.rel("owner", "u_1")
.build();The point is that you state a relationship’s target type and arity once, in the schema. The linkage shape and both link URLs follow from it, so no call site spells them and none can drift.
Using ash-domain? Its ResourceSchema implements these traits already —
see crate::domain, and skip writing them yourself.
Structs§
- Record
- A resource object under construction. Created by
Serializer::record. - Rel
- A relationship, ready to use.
- Serializer
- Serializes one resource’s records into JSON:API resource objects.
Enums§
- NoRelationships
- A resource with no relationships.
Traits§
- Relationship
Def - One relationship your resource declares.
- Schema
- What serialization needs to know about one resource.