5 rust rules available
All five Cursor Rust rules are at least 250 characters: systems programming, error handling, memory safety, async and ownership. The file below combines their checks into one .mdc rule attached to .rs files and Cargo.toml.
Cursor applies project rules stored as .mdc files in .cursor/rules. Each rule's frontmatter (description, globs, alwaysApply) decides whether it is always included, attached to matching files, chosen by the agent from its description, or only used when you @-mention it. Cursor also reads AGENTS.md in the project root and subdirectories for plain-Markdown instructions.
.cursor/rules/rust.mdcStarting point, not a tested configuration for your repository. Attached when files matching the globs are in context (alwaysApply: false with globs). Review the instructions, adapt the file paths and run your project's existing checks.
--- description: "Rust development project conventions" globs: "**/*.rs,**/Cargo.toml" alwaysApply: false --- # Rust instructions for Cursor ## Focus for this project - In async code, never call blocking std I/O or std::thread::sleep; use tokio equivalents or spawn_blocking. - Do not hold a std::sync::Mutex guard across an .await. - Use the error crate the project already uses (thiserror for libraries, anyhow for binaries is common) and add context to errors. ## Rust conventions - Read the edition and rust-version fields in Cargo.toml and stay within them; do not raise either without being asked. - Return Result from fallible functions and propagate with ?. No unwrap() or expect() outside tests, examples and documented invariants. - Borrow (&str, &[T]) in parameters where ownership is not needed, and avoid clone() added only to satisfy the borrow checker; explain any clone that remains. - Every unsafe block needs a // SAFETY: comment stating the invariant it relies on. ## Before you finish - Run cargo fmt --check, cargo clippy --all-targets -- -D warnings and cargo test and report the actual output. If you cannot run them, say so and list the exact commands instead of saying they pass. - Summarize which of the rules above affected the change. - If another attached Cursor rule conflicts with this one, name both rules and follow the one with the narrower globs.
Create your own Cursor rules for Rust and share with the community.
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
Cursor's docs recommend keeping individual rules under 500 lines and splitting large rules into composable ones. Cursor's documentation states that it supports AGENTS.md in the project root and in subdirectories. Use AGENTS.md for plain-Markdown instructions you also want other tools to read, and .mdc rules when you need Cursor's scoping options (globs, description-based selection, always-apply).
Documentation checked 2026-11-05: Cursor docs: Rules
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
You ask Cursor's agent to add an async network client in a Tokio project and want no blocking calls in async code and typed errors.
Add an async fetch_status(url) that times out after 5 seconds.
An async fn using the project's HTTP client and tokio::time::timeout, a typed error for timeout vs request failure, a test, and cargo clippy/test output.
Content reviewed 2026-11-05. Confirm instruction activation in your installed client before relying on it.
Idiomatic Rust error handling: Result and ?, typed errors with thiserror in libraries, anyhow with context in applications, and documented error conditions.