code-quality

A set of Rust code-quality rules for organising and reviewing projects. Rust is a programming language, and these rules vary by project type, such as a library, command-line tool, or web service.

In plain words
What is it for?
Use it when planning Rust modules, choosing names, structuring files, reviewing functions, and selecting quality checks for libraries, applications, CLI tools, or web services.
Why use it?
It gives developers consistent guidance on naming, file structure, responsibility boundaries, and function size. This makes code easier to review and maintain as the project grows.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/tyrchen/cursor-rust-rules/code-quality
Clone the repo
git clone --depth 1 https://github.com/tyrchen/cursor-rust-rules

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 2,083 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.02083
Opus 5 $0.00000 $0.01042
Sonnet 5 $0.00000 $0.00417
Haiku 4.5 $0.00000 $0.00208

Measured 2d ago against content hash 1c675834b3f8, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

code-quality scanned grade A with 0 findings against 26 rules in 11 categories โ€” prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency โ€” measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/rust/core/code-quality.mdc ยท 297 lines

How it starts

The opening of the file, as written. The whole thing โ€” 297 lines โ€” stays where its author put it; the contents beside it link to each section on GitHub.

๐Ÿฆ€ RUST CORE CODE QUALITY STANDARDS

TL;DR: Essential code quality rules for all Rust projects, focusing on maintainable, production-ready code that follows modern Rust 2024 idioms.

๐Ÿ” CODE QUALITY STRATEGY SELECTION

graph TD
    Start["Code Quality Requirements"] --> ProjectType{"Project Type?"}

    ProjectType -->|"Simple Library"| SimpleLib["Simple Library Rules"]
    ProjectType -->|"Complex Application"| ComplexApp["Complex Application Rules"]
    ProjectType -->|"CLI Tool"| CLITool["CLI Tool Rules"]
    ProjectType -->|"Web Service"| WebService["Web Service Rules"]

    SimpleLib --> BasicRules["Basic Quality Rules"]
    ComplexApp --> AdvancedRules["Advanced Quality Rules"]
    CLITool --> BasicRules
    WebService --> AdvancedRules

    BasicRules --> Naming["Naming Strategy"]
    AdvancedRules --> Naming

    Naming --> NamingRules["โ€ข Functionality-based files<br>โ€ข Descriptive specific names<br>โ€ข No implementation suffixes"]

    NamingRules --> Structure["Code Structure"]

    Structure --> StructureRules["โ€ข File-based organization<br>โ€ข Size limitations (500 lines)<br>โ€ข Single responsibility<br>โ€ข Function size (150 lines)"]

    StructureRules --> Safety["Safety Requirements"]

    Safety --> SafetyRules["โ€ข Rust 2024 edition<br>โ€ข No unsafe code<br>โ€ข No unwrap() in production<br>โ€ข Proper error handling"]

    SafetyRules --> Testing["Testing Strategy"]

    Testing --> TestingRules["โ€ข Unit tests same file<br>โ€ข Integration tests separate<br>โ€ข Doc tests with examples"]

    TestingRules --> Verification["Quality Verification"]

    Verification --> Build["cargo build"]
    Verification --> Test["cargo test"]
    Verification --> Clippy["cargo clippy"]

    Build --> AllPass{"All Pass?"}
    Test --> AllPass
    Clippy --> AllPass

    AllPass -->|"Yes"| Success["โœ… Quality Standards Met"]
    AllPass -->|"No"| FixIssues["๐Ÿ”ง Fix Issues"]

    FixIssues --> Verification

    style Start fill:#4da6ff,stroke:#0066cc,color:white
    style ProjectType fill:#ffa64d,stroke:#cc7a30,color:white
    style SimpleLib fill:#4dbb5f,stroke:#36873f,color:white
    style ComplexApp fill:#d94dbb,stroke:#a3378a,color:white
    style CLITool fill:#9f4dbb,stroke:#7a3787,color:white
    style WebService fill:#bb4d4d,stroke:#873636,color:white
    style BasicRules fill:#bbbb4d,stroke:#878736,color:white
    style AdvancedRules fill:#4dbbbb,stroke:#368787,color:white
    style Success fill:#5fbb5f,stroke:#4a8f4a,color:white
    style FixIssues fill:#ff6b6b,stroke:#cc5555,color:white

Read the full file on GitHub ยท 297 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen ยท 297 lines ยท 0 tokens per session scan A 1c675834b3f8

Subscribe to this mod's changes

code-quality is a cursor rule published in the GitHub repository tyrchen/cursor-rust-rules (27 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,083 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.