2022-11-18 12:02:58 +01:00
|
|
|
use axum::{Router, routing::get, extract::{State, FromRef}};
|
2022-10-10 20:40:14 +02:00
|
|
|
|
|
|
|
// This will implement `FromRef` for each field in the struct.
|
|
|
|
#[derive(Clone, FromRef)]
|
|
|
|
struct AppState {
|
|
|
|
auth_token: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
// So those types can be extracted via `State`
|
|
|
|
async fn handler(_: State<String>) {}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let state = AppState {
|
|
|
|
auth_token: Default::default(),
|
|
|
|
};
|
|
|
|
|
2022-11-24 15:43:10 +01:00
|
|
|
let _: axum::Router = Router::new()
|
2022-11-18 12:02:58 +01:00
|
|
|
.route("/", get(handler))
|
|
|
|
.with_state(state);
|
2022-10-10 20:40:14 +02:00
|
|
|
}
|