agentleFS
ahonnahonn/dotfiles/.claude/skills/rust-design-patterns/SKILL.md

rust-design-patterns

Skill62 starsChanged 2 months agoMITView on GitHub

Resolve Rust ownership and lifetime problems or design Rust APIs, resource lifecycles, and FFI boundaries.

3 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

5 rules. 0 are common, 2 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Start from the compiler error, API decision, or code under review.

    line 9
  2. Very specific:

    Check the crate's edition, MSRV, and whether it is a library or binary.

    line 13
  3. Distinctive:

    Follow the crate's existing conventions for errors, builders, and unsafe boundaries before introducing a new pattern.

    line 14
  4. Very specific:

    When a lifetime is too short and no borrow reshaping fits, prefer an owned type over widening lifetimes or adding 'static bounds.

    line 16
  5. Very specific:

    Use the applicable AGENTS.md test mode.

    line 42

“Common” is measured: kept by at least 6 in 10 of the 3 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 Design Patterns

Start from the compiler error, API decision, or code under review. Read only the reference sections that match; the catalog is not a checklist to apply everywhere.

Establish applicability

  • Check the crate's edition, MSRV, and whether it is a library or binary. Library crates carry compatibility constraints (non_exhaustive, lint policy, public types) that binaries do not.
  • Follow the crate's existing conventions for errors, builders, and unsafe boundaries before introducing a new pattern.
  • For borrow checker errors, reshape ownership before reaching for clone, Rc, or Arc. Treat a clone as a deliberate cost, not a way to silence the compiler.
  • When a lifetime is too short and no borrow reshaping fits, prefer an owned type over widening lifetimes or adding 'static bounds.

Read by problem

Problem or decisionReference
Move a value out of &mut, or swap enum variantsownership-patterns.md — mem::take and mem::replace
Borrow two fields of a struct independentlyownership-patterns.md — Struct Decomposition
Choosing shared ownership, or tempted to cloneownership-patterns.md — Rc/Arc Decision Guide
Guaranteed cleanup (locks, files, transactions)ownership-patterns.md — RAII Guards, Finalisation in Destructors
Unsafe code needs a safe boundaryownership-patterns.md — Contain Unsafety in Small Modules
Function parameter types (&str vs &String)api-design.md — Borrowed Types for Arguments
Many optional constructor parametersapi-design.md — Builder Pattern, Default Trait
Distinct types over the same representationapi-design.md — Newtype Pattern
Compile-time state transitionsapi-design.md — Type State Pattern
Public types that must evolve without breaking callersapi-design.md — non_exhaustive, Constructor Conventions
FFI errors, strings, or object lifetimesapi-design.md — FFI Patterns
Dynamic dispatch without boxingidioms.md — On-Stack Dynamic Dispatch
Closure captures, post-setup immutability, Option in iterator chainsidioms.md
A consuming call fails and the caller needs the value backidioms.md — Return Consumed Argument on Error
Reviewing existing Rust for common mistakescommon-pitfalls.md — start with Review Checklist

Examples illustrate the shape of a pattern, not code to paste. Verify version-sensitive behavior against the crate's toolchain.

Complete the change

Use the applicable AGENTS.md test mode. cargo clippy flags most of the unnecessary clones and borrowed-type issues these references describe.

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.