PluginBench
Rule

rust general

via PatrickJS/awesome-cursorrules

Safe, idiomatic Rust development with ownership-first design and robust error handling.

What is rust general?

Establishes patterns for Rust application and library development, covering project structure, ownership, error handling, concurrency, and testing. Use this rule to enforce consistent Rust practices across codebases and avoid common pitfalls like unnecessary cloning, unhandled errors, and unsafe code without justification.

  • Model domain logic with enums and structs; use Option and Result for absence and errors instead of strings or booleans
  • Prefer borrowing over cloning; use owned values only at API boundaries where data must be stored
  • Handle errors with thiserror (libraries) or anyhow (applications); add context at IO, network, and parsing boundaries
  • Use Send and Sync boundaries intentionally; avoid blocking locks across await; propagate cancellation through futures
  • Run cargo fmt and cargo clippy before delivery; add unit and integration tests for logic and public behavior
  • Avoid unwrap/expect outside tests, unsafe code without documentation, and Arc<Mutex<_>> without justification

Applies to

File patterns this rule matches.

["**/*.rs"
Cargo.toml
"Cargo.lock"]
Rule definition (reference)

Source of truth, from the repository.

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.

Related rules

Senior full-stack TypeScript, React, Node.js guidance with clean architecture, testing, and WHY-oriented reasoning.

**/*
41k
via PatrickJS/awesome-cursorrules

Quantitative factor research skills for designing, evaluating, and mining alpha factors in equities markets.

**/*
41k
via PatrickJS/awesome-cursorrules

Android development with Jetpack Compose, clean architecture, and Material Design 3.

**/*
41k
via PatrickJS/awesome-cursorrules

Angular development with Novo Elements UI library using standalone components.

**/*
41k
via PatrickJS/awesome-cursorrules

Expert Angular 18 + TypeScript development with Jest, emphasizing clean code and performance.

**/*
41k
via PatrickJS/awesome-cursorrules

Manage Kubernetes clusters, add-ons, stacks, and credentials via the Ankra CLI platform.

**/*.sh +5
41k
via PatrickJS/awesome-cursorrules