mirror of
https://github.com/tokio-rs/axum.git
synced 2024-11-22 15:17:18 +01:00
43b14a5f02
Co-authored-by: Michael Scofield <mscofield0@tutanota.com> Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
61 lines
1.3 KiB
Rust
61 lines
1.3 KiB
Rust
use axum::{
|
|
async_trait,
|
|
extract::{Request, rejection::ExtensionRejection, FromRequest},
|
|
http::StatusCode,
|
|
response::{IntoResponse, Response},
|
|
routing::get,
|
|
body::Body,
|
|
Extension, Router,
|
|
};
|
|
|
|
fn main() {
|
|
let _: Router = Router::new().route("/", get(handler).post(handler_result));
|
|
}
|
|
|
|
async fn handler(_: MyExtractor) {}
|
|
|
|
async fn handler_result(_: Result<MyExtractor, MyRejection>) {}
|
|
|
|
#[derive(FromRequest)]
|
|
#[from_request(rejection(MyRejection))]
|
|
struct MyExtractor {
|
|
one: Extension<String>,
|
|
#[from_request(via(Extension))]
|
|
two: String,
|
|
three: OtherExtractor,
|
|
}
|
|
|
|
struct OtherExtractor;
|
|
|
|
#[async_trait]
|
|
impl<S> FromRequest<S> for OtherExtractor
|
|
where
|
|
S: Send + Sync,
|
|
{
|
|
// this rejection doesn't implement `Display` and `Error`
|
|
type Rejection = (StatusCode, String);
|
|
|
|
async fn from_request(_req: Request, _state: &S) -> Result<Self, Self::Rejection> {
|
|
todo!()
|
|
}
|
|
}
|
|
|
|
struct MyRejection {}
|
|
|
|
impl From<ExtensionRejection> for MyRejection {
|
|
fn from(_: ExtensionRejection) -> Self {
|
|
todo!()
|
|
}
|
|
}
|
|
|
|
impl From<(StatusCode, String)> for MyRejection {
|
|
fn from(_: (StatusCode, String)) -> Self {
|
|
todo!()
|
|
}
|
|
}
|
|
|
|
impl IntoResponse for MyRejection {
|
|
fn into_response(self) -> Response {
|
|
todo!()
|
|
}
|
|
}
|