agentleFS
Baba01hacker666Baba01hacker666/dummyskills/skills/rust/rust-code-quality/SKILL.md

rust-code-quality

Skill0 starsChanged 2 months agoMITView on GitHub

Guides agents in applying idiomatic Rust architecture: Result/Option handling with ?, avoiding unnecessary clones, custom error types with thiserror.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 3 are distinctive, and 6 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.

  • 6

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when:

    line 14
  2. Very specific:

    Do not use for testing; use rust-testing.

    line 20
  3. Very specific:

    If target_file is missing: ask for target file.

    line 26
  4. Very specific:

    Never leave bare .unwrap() in production library code.

    line 27
  5. Distinctive:

    Follow these numbered actions:

    line 30
  6. Very specific:

    Search for .unwrap() and .expect().

    line 32
  7. Very specific:

    Run cargo check and cargo test.

    line 38
  8. Very specific:

    Never use .unwrap() in production libraries.

    line 41
  9. Distinctive:

    Stop and ask the user when:

    line 68

≈ “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 Code Quality & Idioms

Enforces canonical Rust design: replacing .unwrap() with ? error propagation, defining custom error enums via thiserror, and avoiding unnecessary heap allocations and .clone().

1. Purpose

Refactor Rust code to prevent panics and improve performance.

2. When to Use

Use this skill when:

  • Replacing unsafe .unwrap() or .expect() calls in library code with Result<T, E> and ?.
  • Creating clean, typed error enums.
  • Replacing heap allocations (String) with borrowed slices (&str) in read-only functions.

3. When Not to Use

  • Do not use for testing; use rust-testing.

4. Required Inputs

  • target_file: Path to the Rust source file.

5. Missing-Input Behavior

  1. If target_file is missing: ask for target file.
  2. Never leave bare .unwrap() in production library code.

6. Procedure

Follow these numbered actions:

  1. Action 1: Audit for Panics
    • Search for .unwrap() and .expect().
  2. Action 2: Convert to Result Propagation
    • Return Result<T, AppError> and propagate using ?.
  3. Action 3: Audit Allocations
    • Change fn takes_string(s: String) to fn takes_string(s: &str).
  4. Action 4: Verify Compiler & Tests
    • Run cargo check and cargo test.

7. Decision Rules

  • Never use .unwrap() in production libraries; use ? or handle None.

8. Output Format

Emit the report using this template:

### Rust Code Quality Report: [File]

- **File Modified**: `[path]`
- **Patterns Applied**: [e.g. Error Propagation, Borrowed Slices]
- **Compile Status**: PASS
- **Test Status**: PASS

#### Improvements Made
- [Improvement 1]

9. Verification Checklist

  • No bare .unwrap() calls in modified code.
  • cargo test passes cleanly.
  • No unnecessary .clone() calls.

10. Common Failures and Recovery

Failure SymptomCauseRecovery Action
cannot use ? in function returning ()Function returns unitUpdate function return signature to Result<(), Error>.

11. Stop or Escalation Conditions

Stop and ask the user when:

  • Converting to Result requires modifying public library traits.

12. Examples

Example 1: Successful Execution

Input:

File: src/config.rs
Issue: let val = env::var("PORT").unwrap();

Output:

### Rust Code Quality Report: src/config.rs

- **File Modified**: `src/config.rs`
- **Patterns Applied**: Error Propagation with `?`
- **Compile Status**: PASS
- **Test Status**: PASS

#### Improvements Made
- Replaced `.unwrap()` with `env::var("PORT").map_err(ConfigError::from)?`.

Example 2: Ambiguous or Missing Input

Input:

Improve rust.

Output:

### Rust Code Quality Report: Halted - No File

- **Status**: Halted

Please specify the target Rust file to inspect.

Example 3: Expected Final Output

Output:

### Rust Code Quality Report: src/parser.rs

- **File Modified**: `src/parser.rs`
- **Patterns Applied**: Borrowed Slice Parameters
- **Compile Status**: PASS
- **Test Status**: PASS

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.