pub trait FromRequest: Sized {
type Error: IntoResponse;
// Required method
fn from_request(
ctx: &RequestContext,
req: &mut Request,
) -> impl Future<Output = Result<Self, Self::Error>> + Send;
}Expand description
Trait for types that can be extracted from a request.
This is the core abstraction for request handlers. Each parameter in a handler function implements this trait.
The ctx parameter provides access to the request context, including
asupersync’s capability context for cancellation checkpoints and
budget-aware operations.
§Example
ⓘ
use fastapi_core::{FromRequest, Request, RequestContext};
struct MyExtractor(String);
impl FromRequest for MyExtractor {
type Error = std::convert::Infallible;
async fn from_request(
ctx: &RequestContext,
req: &mut Request,
) -> Result<Self, Self::Error> {
// Check for cancellation before expensive work
let _ = ctx.checkpoint();
Ok(MyExtractor("extracted".to_string()))
}
}Required Associated Types§
Sourcetype Error: IntoResponse
type Error: IntoResponse
Error type when extraction fails.
Required Methods§
Sourcefn from_request(
ctx: &RequestContext,
req: &mut Request,
) -> impl Future<Output = Result<Self, Self::Error>> + Send
fn from_request( ctx: &RequestContext, req: &mut Request, ) -> impl Future<Output = Result<Self, Self::Error>> + Send
Extract a value from the request.
§Parameters
ctx: The request context providing access to asupersync capabilitiesreq: The HTTP request to extract from
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".