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