Skip to navigation
Pass variable Value to a Rust Axum Router Function Handler
27.11.25
get can accept a closure: ``` use axum::{extract::Path, response::IntoResponse, routing::get, Router}; async fn foo(x: u8, Path(name): Path
) -> impl IntoResponse { dbg!(x, name); } #[tokio::main] async fn main() { let x: u8 = 3; let app = Router::new().route("/:name", get(move |name| foo(x, name))); let listener = tokio::net::TcpListener::bind("127.0.0.1:2000") .await .unwrap(); axum::serve(listener, app).await.unwrap(); } ```
https://users.rust-lang.org/t/axum-pass-value-to-router-function/103805
Reply
Anonymous
Information Epoch 1764234664
Worse is better.
Home
Notebook
Contact us