mirror of
https://github.com/tokio-rs/axum.git
synced 2024-11-26 17:17:22 +01:00
9c0a89cd09
* add `#[derive(FromRef)]` * tests * don't support skipping fields probably wouldn't work at all since the whole state likely needs `Clone` * UI tests * changelog * changelog link * revert hello-world example, used for testing * Re-export `#[derive(FromRef)]` * Don't need to return `Result` * use `collect` instead of quoting the iterator * Mention it in axum's changelog
19 lines
468 B
Rust
19 lines
468 B
Rust
use axum_macros::FromRef;
|
|
use axum::{Router, routing::get, extract::State};
|
|
|
|
// 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(),
|
|
};
|
|
|
|
let _: Router<AppState> = Router::with_state(state).route("/", get(handler));
|
|
}
|