pub trait Resource<S: Validators>:
Sized
+ Send
+ 'static {
type Create: FromRequest<S>;
type Update: FromRequest<S>;
const NAME: &'static str;
const PATH: &'static str;
// Required method
fn to_resource(
&self,
state: &S,
ctx: &Context,
) -> Result<ResourceObject, JsonApiError>;
}http and validation only.Expand description
One of your types, as a JSON:API resource.
The two directions a handler needs: reading a validated request document into your type, and writing your type back out as a resource object.
Required Associated Constants§
Required Associated Types§
Sourcetype Create: FromRequest<S>
type Create: FromRequest<S>
What a create body turns into.
Its FromRequest impl owns reading and validating the request, so a
resource whose body is not JSON:API — multipart, form-encoded — needs
no special case here.
Usually Self, but it can be a distinct type when a create carries
different fields from a stored row.
Sourcetype Update: FromRequest<S>
type Update: FromRequest<S>
What an update body turns into. Usually the same as
Self::Create.
Required Methods§
Sourcefn to_resource(
&self,
state: &S,
ctx: &Context,
) -> Result<ResourceObject, JsonApiError>
fn to_resource( &self, state: &S, ctx: &Context, ) -> Result<ResourceObject, JsonApiError>
Write this row out as a resource object, links and linkage included.
state is your application state, for anything resolved at startup
rather than compiled in — a schema registry, a base URL, a feature
flag deciding whether an attribute is exposed. Ignore it when the
resource knows its own shape, which is the usual case.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".