Skip to main content

FromRequest

Trait FromRequest 

Source
pub trait FromRequest:
    Sized
    + Send
    + 'static {
    // Required method
    fn from_request(
        request: Arc<Request>,
    ) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send>>;
}
Expand description

Something a handler parameter can be built from.

Required Methods§

Source

fn from_request( request: Arc<Request>, ) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send>>

Build Self from the request, or fail with the error the client should see (a 400 for a malformed body, a 422 for a failed contract).

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 FromRequest for TokenAbilities

Source§

fn from_request( request: Arc<Request>, ) -> Pin<Box<dyn Future<Output = Result<TokenAbilities, Error>> + Send>>

Source§

impl<T> FromRequest for Option<T>
where T: FromRequest,

An extractor that never fails: Option<T> is None when T would have errored. For inputs that are genuinely optional.

Source§

fn from_request( request: Arc<Request>, ) -> Pin<Box<dyn Future<Output = Result<Option<T>, Error>> + Send>>

Source§

impl<T> FromRequest for Result<T, Error>
where T: FromRequest,

Hands the extraction error to the handler instead of short-circuiting, for actions that want to answer a bad request themselves.

Source§

fn from_request( request: Arc<Request>, ) -> Pin<Box<dyn Future<Output = Result<Result<T, Error>, Error>> + Send>>

Implementors§

Source§

impl FromRequest for Arc<Request>

The whole request.

Source§

impl FromRequest for Bearer

Source§

impl FromRequest for RawBody

Source§

impl<K> FromRequest for Files<K>
where K: StaticName,

Source§

impl<K> FromRequest for Header<K>
where K: StaticName,

Source§

impl<M: Model, K: ParamKey> FromRequest for BoundAs<M, K>

Source§

impl<M: Model> FromRequest for Bound<M>

Source§

impl<T> FromRequest for Form<T>
where T: DeserializeOwned + Send + 'static,

Source§

impl<T> FromRequest for Json<T>
where T: DeserializeOwned + Send + 'static,

Source§

impl<T> FromRequest for Path<T>
where T: DeserializeOwned + Send + 'static,

Source§

impl<T> FromRequest for Query<T>
where T: DeserializeOwned + Send + 'static,

Source§

impl<T> FromRequest for Validated<T>
where T: FormRequest,

Source§

impl<U> FromRequest for AuthenticatedUser<U>
where U: Send + Sync + 'static,

The authenticated user, as a controller parameter.

The framework supplies it, which is why an action can read

ⓘ
pub async fn me(user: AuthenticatedUser<User>) -> Result<Response> {
    Ok(Response::json(user.get()))
}

rather than taking the whole request and digging the user out of it.

Fails with 401 when there is none — which can only happen on a route with no Authenticate middleware in front, so the message says so rather than blaming the caller for a wiring mistake.