Skip to main content
rule

rust-general — Cursor rule: what it does, how to install

This rule guides safe, idiomatic Rust work. It fits projects where .rs, Cargo.toml, and Cargo.lock need consistent coding guidance.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/rust-general.mdc
Open on GitHub

What rust-general does

rust-general covers Rust project layout, ownership, type choices, error handling, async work, and tests. It favors focused crates, small documented public APIs, borrowing when ownership is unnecessary, and explicit domain states with enums and structs. Libraries can use thiserror or the project’s error style, while applications can use anyhow with context at I/O, network, database, and parsing boundaries.

The rule also addresses Send and Sync, cancellation, blocking work in async applications, and test selection. Before delivery, it calls for cargo fmt and cargo clippy; pure logic and public behavior get different test scopes. Its file patterns cover **/*.rs, Cargo.toml, and Cargo.lock, while alwaysApply is false.

Code that keeps a blocking lock across .await conflicts with this guidance. The same applies to undocumented unsafe invariants and discarded errors hidden behind _.

What it helps with

  • organize Rust crates by domain responsibility
  • model absent and fallible values with Option<T> and Result<T, E>
  • attach context at I/O, network, database, or parsing boundaries
  • inspect async code for blocking work across .await
  • run cargo fmt and cargo clippy before delivery

Example prompts for the agent

  • Review this Rust module against the rule for ownership, errors, and project structure.
  • Find unnecessary clones in src/lib.rs and suggest borrowing where the API allows it.
  • Check the async code for blocking locks across .await and hidden cancellation.

How to install rust-general

Manually: put the files in place

.cursor/rules/rust-general.mdc

Frontmatter: description, globs, alwaysApply

Step by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules

Questions about rust-general

How do I install rust-general in Cursor?

Place the rule file at .cursor/rules/rust-general.mdc. Cursor can then apply it to files matching the configured patterns.

What does rust-general do?

It sets guidance for Rust crate structure, ownership, types, errors, concurrency, async code, and testing. It also asks for cargo fmt and cargo clippy before delivery.

Which files does rust-general cover?

Its patterns target **/*.rs, Cargo.toml, and Cargo.lock. The rule is not always active because alwaysApply is false.

Source text

rust-general.mdc · CC0-1.0
---
description: General Rust rules for safe, idiomatic application and library development
globs: ["**/*.rs", "Cargo.toml", "Cargo.lock"]
alwaysApply: false
---

# Rust General Rules

## Project Structure

- Keep crates focused and name modules by domain responsibility.
- Put reusable library code in `src/lib.rs` and binary entry points in `src/main.rs` or `src/bin/`.
- Keep public APIs small and documented.
- Use feature flags deliberately and document non-default features.
- Commit `Cargo.lock` for applications; follow the project convention for libraries.

## Ownership and Types

- Prefer borrowing over cloning when ownership is not needed.
- Use owned values at API boundaries when the callee must store data.
- Model domain states with enums and structs instead of strings or booleans.
- Use `Option<T>` for absence and `Result<T, E>` for fallible operations.
- Avoid `unwrap()` and `expect()` outside tests, examples, and process-startup invariants.

## Error Handling

- Use `thiserror` or project-standard custom errors for libraries.
- Use `anyhow` or project-standard context-rich errors for applications.
- Add context when crossing IO, network, database, or parsing boundaries.
- Do not discard errors with `_` unless explicitly documented.

## Concurrency and Async

- Use `Send` and `Sync` boundaries intentionally.
- Prefer message passing or owned task inputs for async work.
- Do not hold blocking locks across `.await`.
- Use `tokio::task::spawn_blocking` or equivalent for blocking CPU or IO in async applications.
- Propagate cancellation through futures rather than hiding it in detached tasks.

## Testing and Quality

- Run `cargo fmt` and `cargo clippy` before delivery.
- Add unit tests for pure logic and integration tests for public behavior.
- Use property tests for parsers, serializers, and state machines when useful.
- Use benchmarks only after identifying a real performance question.

## Common Mistakes

- Do not fight the borrow checker by adding unnecessary `Arc<Mutex<_>>`.
- Do not expose internal module structure through public APIs by accident.
- Do not allocate in hot loops without measuring.
- Do not use unsafe code unless the invariant is documented and tested.

© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules

Similar IDE rules

All IDE rules for Programming languages →

From the same set210

shopify-theme-dev-liquid A Cursor rule collecting Shopify theme practices across Liquid, JavaScript, CSS, accessibility and performance. Useful when you build a theme and want the agent to keep the structure. ★ 41,024repo stars semiotic-react-dataviz-cursorrules-prompt-file Guides Cursor when building data charts with Semiotic in React, covering HOC props and event callbacks. ★ 41,024repo stars security-devsecops-ssdls-appsec This rule guides Cursor on secure coding, dependencies, access control, and security checks. Use it when you want these requirements applied while editing project files. ★ 41,024repo stars salesforce-apex-cursorrules-prompt-file A Cursor rule that points the agent at Salesforce Apex work: queueables instead of @future, GoF patterns, and almost no comments. ★ 41,024repo stars rtl-right-to-left-i18n-cursorrules-prompt-file A Cursor rule that pushes the agent toward logical CSS and Tailwind utilities instead of left/right. Useful when the app has to run in Arabic, Hebrew, Persian or Urdu. ★ 41,024repo stars ros-ros2 Enforces conventions for ROS and ROS2 workspaces, covering composable nodes, package layout, and launch testing. ★ 41,024repo stars readme-best-practices-cursorrules-prompt-file This rule guides an agent writing project READMEs, from the opening pitch to a runnable Quick Start. Use it when you want documentation readers can scan and try. ★ 41,024repo stars react This rule hands Cursor a set of React conventions: component structure, hooks, state, forms and accessibility. Useful when a project has plenty of .tsx and .jsx and you want one style. ★ 41,024repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor