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