Rule
0 installs · 0 said it worked
Rust coding rules for safe, idiomatic app and library work
A rules file that steers an AI assistant to write safe, idiomatic Rust covering project layout, ownership, error handling, async concurrency, testing, and common pitfalls.
People use this for
- rust coding rules
- rust ownership and error handling guidelines
- write idiomatic rust code for an app
- rules file for safe rust development
- how do i make an ai write safe rust
- Name
rust-coding-rules-for-safe-idiomatic-app-and-library-work- Works with
- Cursor
- License
- CC0(as observed at the source)
- Version
- v1 · updated Nov 29, 2026
Imported on Nov 29, 2026 from github.com . License observed at the source on Nov 29, 2026: CC0.
Are you the author?Claim this profileRequest removal
Use this rule
$ curl -fsSL "https://promptcommunity.dev/api/v1/posts/rust-coding-rules-for-safe-idiomatic-app-and-library-work-6bnq/export/mdc" -o .cursor/rules/rust-coding-rules-for-safe-idiomatic-app-and-library-work.mdcThen open a new session; Cursor picks it up from .cursor/rules/.
Manual install
Save rust-coding-rules-for-safe-idiomatic-app-and-library-work.mdc as .cursor/rules/rust-coding-rules-for-safe-idiomatic-app-and-library-work.mdc for this project or ~/.cursor/rules/rust-coding-rules-for-safe-idiomatic-app-and-library-work.mdc for every project, then start a new session.
Rule
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.rsand binary entry points insrc/main.rsorsrc/bin/. - Keep public APIs small and documented.
- Use feature flags deliberately and document non-default features.
- Commit
Cargo.lockfor 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 andResult<T, E>for fallible operations. - Avoid
unwrap()andexpect()outside tests, examples, and process-startup invariants.
Error Handling
- Use
thiserroror project-standard custom errors for libraries. - Use
anyhowor 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
SendandSyncboundaries intentionally. - Prefer message passing or owned task inputs for async work.
- Do not hold blocking locks across
.await. - Use
tokio::task::spawn_blockingor 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 fmtandcargo clippybefore 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.
No result recorded yet. Added it? File a Tried-it report so the next person knows how it went in your editor.
Tried it
Reports from people who added this rule to their editor. They roll up into the badges above.
No one has filed a report yet. Try the prompt and be the first.
Related rules
- Autonomous coding agent that builds a verified app-builder harness
Master system prompt that directs an autonomous senior Python engineer to build a spec-driven, evidence-traced app-builder harness milestone by milestone without asking questions.
Coding · @mahfuzahmedog
- Find silent exception-handling smells in Python code
Scans Python files offline with ast to flag bare or swallowed excepts, silent fallbacks, lost causes, and other error-hiding patterns, returning file:line findings with severity and fix recipes.
Coding · @f
- Agent that writes, runs, and repairs tests after code changes
A system prompt defining a test-writer-fixer agent that writes unit, integration, and end-to-end tests, runs suites, analyzes failures, and repairs tests without weakening them.
Coding · @ersinyilmaz
- Quality engineering agent role for risk-based test strategy and CI quality gates
A senior quality engineering role prompt that guides an assistant through risk-based test strategy, test automation architecture, CI/CD quality gates, edge-case analysis, and defect management, writing results to a TODO checklist file.
Coding · @wkaandemir
- Context7 agent that answers library questions from up-to-date docs
Agent instructions that force lookup of current library documentation via Context7 before answering framework or package questions, and check workspace versions for upgrades.
Coding · @joembolinas
License: CC0v1 · published Nov 29, 2026
Comments
No comments yet. If you tried this prompt, say how it went.