mirror of
https://github.com/tokio-rs/axum.git
synced 2024-12-29 07:48:39 +01:00
0b26411f39
* Implement `Service` for `Router<(), B>` * wip * wip * fix some tests * fix examples * fix doc tests * clean up docs * changelog * fix * also call `with_state` when converting `MethodRouter` into a `MakeService` * suggestions from review
37 lines
733 B
Rust
37 lines
733 B
Rust
use std::convert::Infallible;
|
|
use axum::{
|
|
extract::State,
|
|
response::{IntoResponse, Response},
|
|
routing::get,
|
|
Router,
|
|
};
|
|
use axum_macros::FromRequest;
|
|
|
|
fn main() {
|
|
let _: axum::Router = Router::new()
|
|
.route("/a", get(|_: Extractor| async {}))
|
|
.with_state(AppState::default());
|
|
}
|
|
|
|
#[derive(Clone, Default, FromRequest)]
|
|
#[from_request(rejection(MyRejection))]
|
|
struct Extractor {
|
|
state: State<AppState>,
|
|
}
|
|
|
|
#[derive(Clone, Default)]
|
|
struct AppState {}
|
|
|
|
struct MyRejection {}
|
|
|
|
impl From<Infallible> for MyRejection {
|
|
fn from(err: Infallible) -> Self {
|
|
match err {}
|
|
}
|
|
}
|
|
|
|
impl IntoResponse for MyRejection {
|
|
fn into_response(self) -> Response {
|
|
().into_response()
|
|
}
|
|
}
|