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§
Sourcefn from_request(
ctx: &RequestContext,
) -> impl Future<Output = Result<Self>> + Send
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>.
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.
fn from_request( ctx: &RequestContext, ) -> impl Future<Output = Result<Self>> + Send
Implementors§
impl FromRequest for BearerToken
impl FromRequest for Cache
impl FromRequest for LastEventId
impl FromRequest for Logger
impl FromRequest for Throttler
impl<S> FromRequest for State<S>
impl<T> FromRequest for Form<T>
impl<T> FromRequest for Json<T>where
T: DeserializeOwned + Send,
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 Requestif the body was already consumed, exceeds the size cap, or could not be read.422 Unprocessable Entityif the body is not valid JSON forT.