Skip to main content

FromRequest

Trait FromRequest 

Source
pub trait FromRequest: Sized + Send {
    // Required method
    fn from_request(
        ctx: &RequestContext,
    ) -> impl Future<Output = Result<Self>> + Send;
}
Expand description

Produces a value from the current request to satisfy a handler parameter.

Implemented directly by built-in extractors and generated by #[tork::dependency] for user dependencies. Resolution is always statically dispatched. The returned future is Send so the enclosing handler future is Send, as required by the server.

Required Methods§

Source

fn from_request( ctx: &RequestContext, ) -> impl Future<Output = Result<Self>> + Send

Resolves Self from the request context.

An Err short-circuits request handling and is rendered as an HTTP error response.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: Send + Sync + 'static> FromRequest for Arc<T>

Injects any resource registered as Arc<T>.

Registering a shared value as Arc<T> (for example a loaded configuration) lets a handler or service take it by Arc<T>, cloning only the pointer per request. This is the idiomatic way to share immutable state cheaply, since the orphan rules prevent a downstream crate from implementing FromRequest for Arc<T> itself.

Source§

fn from_request( ctx: &RequestContext, ) -> impl Future<Output = Result<Self>> + Send

Implementors§

Source§

impl FromRequest for BearerToken

Source§

impl FromRequest for Cache

Source§

impl FromRequest for LastEventId

Source§

impl FromRequest for Logger

Source§

impl FromRequest for Throttler

Source§

impl<S> FromRequest for State<S>
where S: Clone + Send + Sync + 'static,

Source§

impl<T> FromRequest for Form<T>
where T: DeserializeOwned + Validate<Context = ()> + Send,

Source§

impl<T> FromRequest for Json<T>

Deserializes the request body as JSON.

The body is buffered with a size cap of MAX_BODY_BYTES to guard against memory-exhaustion attacks, then parsed into T.

§Errors

  • 400 Bad Request if the body was already consumed, exceeds the size cap, or could not be read.
  • 422 Unprocessable Entity if the body is not valid JSON for T.
Source§

impl<T> FromRequest for Multipart<T>
where T: FromMultipart + Send,

Source§

impl<T> FromRequest for SseResume<T>
where T: FromStr + Send,

Source§

impl<T> FromRequest for Valid<T>
where T: DeserializeOwned + Validate<Context = ()> + Send,