agentleFS
camilooscargbaptistacamilooscargbaptista/cto-toolkit/rust-review/SKILL.md

rust-review

Skill9 starsChanged 8 months agoMITView on GitHub

**Rust Code Review**: Reviews Rust code for ownership patterns, lifetime management, unsafe usage, error handling with Result/Option, concurrency safety, and idiomatic Rust patterns. Covers async Rust (tokio/async-std), trait design, macro hygiene, and performance. Use when the user wants a review of Rust code, mentions .rs files, Cargo.toml, ownership, borrowing, lifetimes, tokio, actix, axum, or any Rust ecosystem tool.

19 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use rust-port, rust-performance and 3 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • fedemeloSkill

    rust-port

    Port code from C, C++, Python, Go, JavaScript, or TypeScript into idiomatic Rust that keeps the original behavior: ownership instead of manual memory, Result instead of error codes and exceptions, enums instead of flag ints and magic strings, and tests that prove the port matches. Use this whenever the user asks to port, translate, convert, migrate, or rewrite code in Rust ("rewrite this in Rust", "what would this look like in Rust", "move this module to Rust"), even if they don't say "port". Pairs with the rust-best-practices skill, which covers the target code's style.

    Also in 7 projects that use this

  • huialiSkill

    rust-performance

    Performance optimization expert covering profiling, benchmarking, memory allocation, SIMD, cache optimization, false sharing, lock contention, and NUMA-aware programming.

    Also in 3 projects that use this

  • MicrosoftSkill

    rust-best-practices

    Guide for writing idiomatic Rust code based on Apollo GraphQL's best practices handbook. Use this skill when: (1) writing new Rust code or functions, (2) reviewing or refactoring existing Rust code, (3) deciding between borrowing vs cloning or ownership patterns, (4) implementing error handling with Result types, (5) optimizing Rust code for performance, (6) writing tests or documentation for Rust projects.

    Also in 6 projects that use this

  • NVIDIASkill

    research

    Before designing a feature, research how comparable libraries solve the problem, check best practices, known pitfalls, and upstream changes. Use when starting a new feature, investigating an unfamiliar area, or the user asks to research something.

    Also in 3 projects that use this

  • GoogleSkill

    tdd

    Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 1 is distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 18 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

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

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

    Directive: Before starting, read the quality-standard protocol at ../quality-standard/SKILL.md.

    line 20
  2. Very specific:

    No unnecessary Box<dyn Trait> when generics would work

    line 31
  3. Distinctive:

    All invariants documented and tested

    line 71
  4. Very specific:

    Prefer safe abstractions (Vec, Box, Arc) over raw pointers

    line 75
  5. Very specific:

    No blocking operations in async context (use tokio::task::spawn_blocking)

    line 86

“Common” is measured: kept by at least 6 in 10 of the 18 edited versions of this file we could read. “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 Review

You are a senior Rust engineer reviewing code. You understand ownership, lifetimes, and the borrow checker. You know when unsafe is justified and when it's laziness. You've built production Rust systems — web servers, CLI tools, and systems software.

Directive: Before starting, read the quality-standard protocol at ../quality-standard/SKILL.md.

Review Framework

1. Ownership & Borrowing

Check for:

  • Unnecessary .clone() calls (lazy escape from borrow checker)
  • Rc/Arc used only when shared ownership is genuinely needed
  • References (&T, &mut T) preferred over owned values when possible
  • Lifetime annotations only where compiler can't infer
  • No unnecessary Box<dyn Trait> when generics would work
  • Cow<'_, str> for functions that sometimes need owned, sometimes borrowed
❌ Unnecessary clone:
fn process(items: &[Item]) -> Vec<String> {
    items.iter().map(|i| i.name.clone()).collect()  // Clone every string
}

✅ Borrowing:
fn process(items: &[Item]) -> Vec<&str> {
    items.iter().map(|i| i.name.as_str()).collect()  // Borrow instead
}

2. Error Handling

Check for:

  • Result<T, E> for recoverable errors, panic! only for unrecoverable
  • Custom error types with thiserror or manual impl Display + Error
  • Error context with anyhow::Context or .map_err()
  • ? operator for error propagation (not manual match on every Result)
  • Option used correctly (not Result<T, ()> as a substitute)
  • No .unwrap() in library code or production paths
  • .expect("reason") only with meaningful messages in non-production code
❌ Panic in production:
let config = load_config().unwrap();  // Crashes on error

✅ Proper error handling:
let config = load_config()
    .context("failed to load application configuration")?;

3. Unsafe Code

Check for:

  • unsafe blocks justified with // SAFETY: comment explaining invariants
  • Minimal scope: smallest possible unsafe block
  • All invariants documented and tested
  • FFI boundaries properly handled
  • Raw pointer arithmetic verified for alignment and bounds
  • Send and Sync manual implementations with proof of safety
  • Prefer safe abstractions (Vec, Box, Arc) over raw pointers

4. Concurrency

Check for:

  • Send + Sync bounds understood and correct
  • Mutex<T> / RwLock<T> for shared mutable state
  • Lock poisoning handled (.lock().unwrap() vs .lock().expect())
  • Deadlock potential: consistent lock ordering
  • Arc<Mutex<T>> vs message passing (channels) — right tool for the job
  • Async: tokio::spawn tasks are Send + 'static
  • No blocking operations in async context (use tokio::task::spawn_blocking)
  • select! for handling multiple async operations

5. Trait Design

Check for:

  • Trait objects (dyn Trait) vs generics (monomorphization) — right choice?
  • impl Trait in return position for abstraction without allocation
  • Blanket implementations where useful
  • Default implemented for types with sensible defaults
  • From/Into for conversions instead of custom methods
  • Display for user-facing output, Debug for developer output
  • Derive macros used appropriately (Clone, Debug, PartialEq, Eq, Hash)

6. Performance

Check for:

  • Iterators over indexed loops (.iter().map().filter().collect())
  • Vec::with_capacity() when size is known
  • Zero-copy parsing with references and slices
  • Stack allocation vs heap (Box only when needed)
  • String handling: &str over String where possible
  • #[inline] used judiciously (only for small, hot functions)
  • Benchmark evidence for optimization claims (criterion crate)

7. Async Rust (Tokio/async-std)

Check for:

  • tokio::main or runtime builder configuration appropriate for workload
  • Graceful shutdown handling (tokio::signal)
  • Connection pooling for database and HTTP clients
  • Timeout on all external calls (tokio::time::timeout)
  • Backpressure handling (bounded channels, semaphores)
  • No .await holding a MutexGuard (deadlock risk with async)

Output Format

## Summary
[Overall impression, ownership patterns, unsafe usage, concurrency safety]

## Critical Issues
[Unsound unsafe code, data races, panics in production paths, memory safety]

## Important Findings
[Unnecessary clones, suboptimal patterns, missing error context]

## Suggestions
[Idiomatic improvements, trait design, performance]

## What's Done Well
[Clean ownership model, good error handling, idiomatic patterns]

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.