pub trait FromHttpContext:
Sized
+ Send
+ 'static {
// Required method
fn from_http_context<'life0, 'async_trait>(
ctx: &'life0 dyn IHttpContext,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Trait for constructing a request struct from the HTTP context.
Implemented automatically by the #[get], #[post], #[put], #[delete]
proc macros for request types. Custom implementations are also supported.
§Automatic implementation
For POST/PUT/PATCH routes, the macro will attempt serde_json::from_slice
on the request body. For GET/DELETE routes with path parameters, the macro
will extract parameters from ctx.request().route_params() by field name.
§Manual implementation
ⓘ
#[async_trait::async_trait]
impl FromHttpContext for MyRequest {
async fn from_http_context(ctx: &dyn IHttpContext) -> Result<Self> {
// custom construction logic
}
}Required Methods§
fn from_http_context<'life0, 'async_trait>(
ctx: &'life0 dyn IHttpContext,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".