agentleFS
dawidpereiradawidpereira/rust-skills/skills/rust-quality/SKILL.md

rust-quality

Skill0 starsChanged 8 months agoMITView on GitHub

Rust code quality — linting, project structure, anti-patterns, and advanced testing tools. Use when configuring clippy lints, organizing modules and workspaces, reviewing code for common Rust anti-patterns like excessive cloning or unwrap abuse, or setting up proptest, mockall, or criterion. Also use when setting up a new Rust project's Cargo.toml with recommended lint and profile settings. For unit and integration test strategy, see rust-tests.

The file

We split this skill into the rules it gives an agent

12 rules. About 0 are common, 3 are distinctive, and 9 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Keep main.rs thin, logic in lib.rs for testability.

    line 183
  2. Very specific:

    Use pub use re-exports in mod.rs to create clean public APIs.

    line 185
  3. Very specific:

    Create a prelude module for commonly used types in libraries.

    line 186
  4. Very specific:

    Put multiple binaries in src/bin/.

    line 187
  5. Very specific:

    Use mod.rs for complex modules, adjacent files for simple ones.

    line 188
  6. Very specific:

    Create src/lib.rs with module declarations and src/main.rs as thin entry point.

    line 195
  7. Very specific:

    Add rustfmt.toml with edition = "2024" and max_width = 100.

    line 196
  8. Distinctive:

    Check the anti-patterns index for common issues.

    line 202
  9. Distinctive:

    Verify all public items have documentation.

    line 203
  10. Very specific:

    Look for .unwrap() in non-test code (use ?

    line 205
  11. Distinctive:

    Ensure dependencies are behind traits for testability.

    line 206
  12. Very specific:

    Run cargo clippy -- -D warnings and fix all warnings.

    line 207

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Rust Quality

Core Question

Is this tested, linted, and organized for the next developer?

Quick Decisions

SituationAction
New projectApply default Cargo.toml settings below
Adding a featureWrite tests first — see rust-tests for unit/integration strategy
Reviewing codeCheck anti-patterns index
Setting up CIcargo fmt --check && cargo clippy -- -D warnings && cargo test
Organizing modulesFeature-based, flat for small projects
BenchmarkingUse criterion, never Instant::now()
Mocking dependenciesExtract traits, use mockall
Property testingUse proptest for roundtrip/invariant checks
Workspace setupInherit lints and deps from workspace root

Default Cargo.toml Settings

Apply these settings to every new Rust project:

[package]
edition = "2024"
rust-version = "1.85"

[lints.clippy]
correctness = "deny"
suspicious = "warn"
style = "warn"
complexity = "warn"
perf = "warn"

[profile.release]
opt-level = 3
lto = "fat"
codegen-units = 1
panic = "abort"
strip = true

[profile.dev.package."*"]
opt-level = 3

For workspaces, define lints at the root and inherit:

# workspace Cargo.toml
[workspace.lints.clippy]
correctness = "deny"
suspicious = "warn"
style = "warn"
complexity = "warn"
perf = "warn"

# member Cargo.toml
[lints]
workspace = true

Clippy Lint Levels

Deny: correctness

Hard errors for code that is outright wrong. Catches infinite iterators, NaN comparisons, impossible conditions, and invalid regex. Never allow these.

[lints.clippy]
correctness = "deny"

Warn: suspicious, style, complexity, perf

Soft warnings for likely bugs, non-idiomatic patterns, unnecessary complexity, and performance anti-patterns.

[lints.clippy]
suspicious = "warn"
style = "warn"
complexity = "warn"
perf = "warn"

Selective: pedantic

Enable pedantic as a baseline, then disable noisy lints:

[lints.clippy]
pedantic = "warn"
missing_errors_doc = "allow"
missing_panics_doc = "allow"
module_name_repetitions = "allow"
must_use_candidate = "allow"
too_many_lines = "allow"

Additional recommended lints

[lints.clippy]
undocumented_unsafe_blocks = "warn"

[lints.rust]
missing_docs = "warn"

For published crates, add cargo = "warn" to catch missing metadata and wildcard dependencies.

Project Structure Quick Reference

Small projects (< 10 files): flat

src/
├── main.rs
├── lib.rs
├── config.rs
├── database.rs
└── error.rs

Medium projects (10-20 files): feature-based modules

src/
├── main.rs          # Thin entry point
├── lib.rs           # Re-exports, module declarations
├── user/
│   ├── mod.rs
│   ├── model.rs
│   ├── repository.rs
│   └── service.rs
├── order/
│   ├── mod.rs
│   ├── model.rs
│   └── service.rs
└── shared/
    ├── mod.rs
    ├── error.rs
    └── database.rs

Large projects: workspace

my-project/
├── Cargo.toml            # [workspace] with shared lints/deps
├── crates/
│   ├── core/
│   ├── api/
│   └── cli/
└── tests/

Visibility rules

ScopeKeywordUse for
Public APIpubTypes and functions users need
Crate-internalpub(crate)Shared implementation details
Parent-onlypub(super)Sibling submodule helpers
Private(default)Everything else

Key patterns

  • Keep main.rs thin, logic in lib.rs for testability.
  • Organize by feature (user/, order/), not by type (models/, services/).
  • Use pub use re-exports in mod.rs to create clean public APIs.
  • Create a prelude module for commonly used types in libraries.
  • Put multiple binaries in src/bin/.
  • Use mod.rs for complex modules, adjacent files for simple ones.

Usage Scenarios

Scenario 1: Setting up a new Rust project

  1. Apply default Cargo.toml settings (edition, lints, profiles).
  2. Create src/lib.rs with module declarations and src/main.rs as thin entry point.
  3. Add rustfmt.toml with edition = "2024" and max_width = 100.
  4. Set up CI: cargo fmt --check && cargo clippy -- -D warnings && cargo test.
  5. Structure tests: #[cfg(test)] mod tests in each file, tests/ for integration.

Scenario 2: Reviewing Rust code for quality

  1. Check the anti-patterns index for common issues.
  2. Verify all public items have documentation.
  3. Confirm tests follow arrange/act/assert with descriptive names.
  4. Look for .unwrap() in non-test code (use ? or .expect() with context).
  5. Ensure dependencies are behind traits for testability.
  6. Run cargo clippy -- -D warnings and fix all warnings.

Scenario 3: Adding tests to existing code

  1. Decide test boundaries: see rust-tests → Quick Decisions for unit vs integration.
  2. Property tests: proptest! for roundtrip, idempotence, and invariant properties.
  3. Mocking: extract dependencies into traits, use mockall for mock generation.
  4. Benchmarks: criterion in benches/, with black_box to prevent optimization.
  5. Async tests: #[tokio::test] for async functions.

Reference Index

ReferenceCovers
references/testing.mdProptest, mockall, criterion, tokio::test, RAII fixtures, doctests. For unit/integration test strategy and organization, see rust-tests
references/linting.mdClippy lint levels, pedantic config, workspace lints, missing_docs, unsafe docs, cargo fmt in CI
references/project.mdlib/main split, feature modules, visibility, re-exports, prelude, workspaces, dependency inheritance
references/anti-patterns.md15 common anti-patterns with bad/good examples and "when acceptable" guidance

Cross-References

  • Error handling patterns: see the rust-errors skill for thiserror, anyhow, Result<T, E>, and error context chains.
  • API design and naming conventions: see the rust-api skill for builder pattern, newtype, From/Into, sealed traits, #[non_exhaustive], and naming (references/naming.md).
  • Unit & integration testing strategy: see the rust-tests skill for test boundaries, module organization, test builders, error path testing, and integration test isolation.
  • Performance optimization: see the rust-perf skill for profiling, memory layout, SIMD, and release profile tuning.
  • Async patterns: see the rust-async skill for tokio runtime, channels, cancellation, and structured concurrency.
  • Logging and observability: see the rust-tracing skill for tracing setup, structured logging, #[instrument], RUST_LOG, and OpenTelemetry integration.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.