Last active
December 27, 2022 16:16
-
-
Save hmeine/e9a20fd8337e4bc5096ecfacc2c6d9d6 to your computer and use it in GitHub Desktop.
Minimal example reproducing axum compilation problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "minimal_axum" | |
version = "0.1.0" | |
edition = "2021" | |
[dependencies] | |
axum = { version = "0.6.1" } | |
tokio = { version = "1", features = ["full"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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