Axum Example not working
Open
Nobody has claimed this yet.
needs-repro
- Dominant language
- Rust
- Stars
- 9.9k
- Forks
- 735
- Avg merge
- 6h 36m
- Merged PRs (30d)
- 8
Description
[DatabaseConnection] is passed as State .with_state(state) in Axum Server but this don't work. [DatabaseConnection] can't be shared across threads.
In examples/axum_example/api/src/lib.rs
...
#[derive(Clone)]
struct AppState {
templates: Tera,
conn: DatabaseConnection,
}
...
dotenvy::dotenv().ok();
let db_url = env::var("DATABASE_URL").expect("DATABASE_URL is not set in .env file");
let conn = Database::connect(db_url)
.await
.expect("Database connection failed");
let templates = ...
let state = AppState { templates, conn };
...
let app = Router::new()
.route("/", get(list_posts).post(create_post))
...
.with_state(state);
...
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in examples/axum_example/api/src/lib.rs and inspect how AppState, DatabaseConnection, and .with_state(state) are assembled. Run the Axum example to reproduce the thread-sharing error, then verify that the example builds and starts successfully with the database connection in its state.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100