agentleFS
CassetteTapeCrackleCassetteTapeCrackle/claude-starters/skills/clean-code-rust/SKILL.md

clean-code-rust

Skill1 starsChanged 3 months agoMITView on GitHub

Use when writing or reviewing Rust — deeper idioms (ownership/borrows, error handling with thiserror/anyhow, avoiding unwrap and Rc<RefCell>, iterator style, newtypes).

The file

Files
SKILL.md

Clean-code Rust (depth)

On top of the base rules (edition 2021, clippy -D warnings, rustfmt, cargo test).

Errors

  • Libraries: define an error enum with thiserror, return Result<_, MyError>, propagate with ?.
  • Binaries: anyhow::Result + .context("..."). Never .unwrap()/.expect() outside tests or justified startup.

Ownership & borrows

  • Take &T/&mut T in function signatures; own only when you must. Return owned values.
  • Reach for Rc<RefCell<_>> only when shared mutability is genuinely required — it's a smell as a default; prefer restructuring ownership or passing &mut.
  • Newtypes (struct UserId(u64)) over bare primitives for meaning + type safety.

Style

  • Iterators/adapters over manual index loops; ? over match-on-error pyramids.
  • Producing many values: return impl Iterator<Item = T> and let the caller decide whether to collect().
  • A validated newtype has a constructor returning Result (Normalized::new(v)?), so holding one proves the check ran.
  • Derive (Debug, Clone, PartialEq) rather than hand-writing. impl Trait in args for flexibility.
  • clippy::pedantic is a good aspiration; silence lints with a reason, never blanket-allow.

Smells

  • .clone() sprinkled to dodge the borrow checker → rethink ownership.
  • unsafe without // SAFETY: → not acceptable.
  • Stringly-typed IDs/states → newtype or enum.

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.