2022-09-23 23:50:50 +02:00
|
|
|
use axum::{
|
2023-08-03 10:23:18 +02:00
|
|
|
extract::{FromRef, State},
|
2022-09-23 23:50:50 +02:00
|
|
|
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| async {}))
|
|
|
|
.route("/b", get(|_: InnerState| async {}))
|
2022-11-18 12:02:58 +01:00
|
|
|
.route("/c", get(|_: AppState, _: InnerState| async {}))
|
|
|
|
.with_state(AppState::default());
|
2022-09-23 23:50:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, FromRequestParts)]
|
|
|
|
#[from_request(via(State))]
|
|
|
|
enum AppState {
|
|
|
|
One,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for AppState {
|
|
|
|
fn default() -> AppState {
|
|
|
|
Self::One
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(FromRequestParts)]
|
|
|
|
#[from_request(via(State), state(AppState))]
|
|
|
|
enum InnerState {}
|
|
|
|
|
|
|
|
impl FromRef<AppState> for InnerState {
|
|
|
|
fn from_ref(_: &AppState) -> Self {
|
2023-08-03 10:23:18 +02:00
|
|
|
todo!("🤷")
|
2022-09-23 23:50:50 +02:00
|
|
|
}
|
|
|
|
}
|