2022-09-23 23:50:50 +02:00
|
|
|
use axum::{
|
|
|
|
extract::{State, FromRef},
|
|
|
|
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 {
|
|
|
|
todo!(":shrug:")
|
|
|
|
}
|
|
|
|
}
|