Skip to content

Instantly share code, notes, and snippets.

@hmeine
Last active December 27, 2022 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hmeine/e9a20fd8337e4bc5096ecfacc2c6d9d6 to your computer and use it in GitHub Desktop.
Save hmeine/e9a20fd8337e4bc5096ecfacc2c6d9d6 to your computer and use it in GitHub Desktop.
Minimal example reproducing axum compilation problem
[package]
name = "minimal_axum"
version = "0.1.0"
edition = "2021"
[dependencies]
axum = { version = "0.6.1" }
tokio = { version = "1", features = ["full"] }
use std::sync::{Arc, Mutex};
use axum::{extract::State, routing::get, Router};
#[tokio::main]
async fn main() {
let state = Arc::new(Mutex::new(AppState::default()));
let app = Router::new()
.route("/", get(example_handler))
.with_state(state);
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(app.into_make_service())
.await
.unwrap();
}
#[derive(Default)]
struct AppState;
impl AppState {
async fn other(&self) {}
}
async fn example_handler(State(state): State<Arc<Mutex<AppState>>>) {
let state = state.lock().unwrap();
state.other().await // without async/await, this compiles
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment