pub trait FromRequest<S>:
Sized
+ Send
+ Sync
+ 'static {
// Required method
fn from_request(
request: Request,
state: &S,
ctx: &Context,
) -> impl Future<Output = Result<Self, Errors>> + Send;
}http only.Expand description
Build Self from a request.
Implemented on the type a handler wants — the parsed body, an
authenticated actor, a resolved tenant. Whatever it produces is attached
to the Context with Context::with, so downstream code reads it
back with Context::extract rather than threading a parameter.
The Context passed in is the request’s own, so errors can carry the
correlation id: build them with JsonApiError::invalid and friends.
Required Methods§
Sourcefn from_request(
request: Request,
state: &S,
ctx: &Context,
) -> impl Future<Output = Result<Self, Errors>> + Send
fn from_request( request: Request, state: &S, ctx: &Context, ) -> impl Future<Output = Result<Self, Errors>> + Send
Read the request into Self.
Consumes the request, since reading a body is a one-shot operation.
state is your application state, so an implementation can reach the
validator, a connection pool, or anything else it needs.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl<S: Sync> FromRequest<S> for Upload
Reads any request body as an upload, capped at MAX_UPLOAD.
Deliberately does not check the media type — an upload is not a JSON:API
document, so the JSON:API media-type check would reject every real file. Use
Upload::accepting from your own impl when the endpoint should only
take certain types.