Production-Ready Rule
•
src/**/*.rs, tests/**/*.rs
Rust, Axum & Tokio High-Performance .cursorrules (.mdc)
High-performance .cursorrules and .cursor/rules/*.mdc configuration for Rust, Axum, and Tokio. Enforce idiomatic error handling with thiserror/anyhow, zero-copy deserialization, and strict async discipline.
.cursor/rules/rust-axum.mdc
---
description: Rust 2024 edition, Axum web framework, Tokio async, and SQLx standards
globs: src/**/*.rs, tests/**/*.rs
alwaysApply: false
---
# Rust & Axum Engineering Standards
## Error Handling & Robustness
- Never call .unwrap() or .expect() in production request handlers or library code.
- Define a unified application error enum using `thiserror` and implement Axum's `IntoResponse`.
- Use `anyhow` solely for application entry points (main.rs) or tests.
- Always map database and third-party errors into structured domain error variants.
## Async & Concurrency Discipline (Tokio)
- Never execute blocking CPU-heavy operations or synchronous file/network I/O on async worker threads.
- Offload blocking work to `tokio::task::spawn_blocking`.
- Keep mutex lock guards tightly scoped; never hold a std::sync::MutexGuard across an .await point.
## Axum Routing & State
- Group related endpoints into modular routers merged into the main application Router.
- Pass shared application state via `axum::extract::State(state)` with an Arc-wrapped struct.
- Validate request payloads with typed extractors (`Json`, `Query`, `Path`).
⭐
Using this rule in your open-source project? Reference in your README:
https://cursor.pacebowl.com/rules/rust-axum
Frequently Asked Questions & Implementation Notes
How does this rule eliminate panic crashes in production?
It strictly bans unwrap() and expect() in request handlers, requiring the AI to propagate errors via the Result
How does it protect async Tokio thread pools?
It prevents blocking std I/O calls on async runtimes and warns against holding non-async mutex locks across .await boundaries, preventing thread starvation and deadlocks.