pub trait RequestDecorator:
Send
+ Sync
+ 'static {
type Output: Send + 'static;
// Required method
fn extract(
ctx: &RequestContext,
parts: &Parts,
) -> Result<Self::Output, HttpException>;
}Expand description
Request Decorator Trait
A custom request decorator (extractor) defines custom logic for extracting data from an incoming HTTP request. This is the foundation for creating custom extractors beyond the built-in ones.
§Type Parameters
Self: The decorator type implementing the trait
§Associated Types
Output: The type that gets extracted from the request
§Example
struct UserAgent;
impl RequestDecorator for UserAgent {
type Output = String;
fn extract(ctx: &RequestContext, parts: &Parts) -> Result<Self::Output, HttpException> {
parts.headers
.get("user-agent")
.and_then(|h| h.to_str().ok())
.map(|s| s.to_string())
.ok_or_else(|| HttpException::bad_request("Missing User-Agent"))
}
}Required Associated Types§
Required Methods§
fn extract( ctx: &RequestContext, parts: &Parts, ) -> Result<Self::Output, HttpException>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.