2022-09-23 23:50:50 +02:00
|
|
|
use axum::{
|
|
|
|
extract::{FromRef, State},
|
|
|
|
routing::get,
|
|
|
|
Router,
|
|
|
|
};
|
|
|
|
use axum_macros::FromRequestParts;
|
|
|
|
|
|
|
|
fn main() {
|
2022-11-24 15:43:10 +01:00
|
|
|
let _: axum::Router = Router::new()
|
2022-09-23 23:50:50 +02:00
|
|
|
.route("/a", get(|_: AppState, _: InnerState, _: String| async {}))
|
|
|
|
.route("/b", get(|_: AppState, _: String| async {}))
|
2022-11-18 12:02:58 +01:00
|
|
|
.route("/c", get(|_: InnerState, _: String| async {}))
|
|
|
|
.with_state(AppState::default());
|
2022-09-23 23:50:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Default, FromRequestParts)]
|
|
|
|
#[from_request(via(State))]
|
|
|
|
struct AppState {
|
|
|
|
inner: InnerState,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Default, FromRequestParts)]
|
|
|
|
#[from_request(via(State), state(AppState))]
|
|
|
|
struct InnerState {}
|
|
|
|
|
|
|
|
impl FromRef<AppState> for InnerState {
|
|
|
|
fn from_ref(input: &AppState) -> Self {
|
|
|
|
input.inner.clone()
|
|
|
|
}
|
|
|
|
}
|