rust-design-patterns

rust-design-patterns is a skill for Claude Code, Codex from ahonn/dotfiles. It costs 77 tokens per session (2,047 once invoked), scanned A, original, MIT.

A guide to Rust idioms and design patterns, including ownership, borrowing, error handling, API design, and resource cleanup.

In plain words
What is it for?
Use it when writing or reviewing Rust code, fixing borrow-checker or lifetime errors, designing APIs, or working with unsafe code and foreign-function interfaces.
Why use it?
It helps developers solve Rust-specific problems and choose code structures that fit the language.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/ahonn/dotfiles/rust-design-patterns
Any agent
npx skills add ahonn/dotfiles --skill rust-design-patterns
Clone the repo
git clone --depth 1 https://github.com/ahonn/dotfiles

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for rust-design-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/ahonn/dotfiles/rust-design-patterns.svg)](https://agentmods.dev/skills/ahonn/dotfiles/rust-design-patterns)
Your own site
<a href="https://agentmods.dev/skills/ahonn/dotfiles/rust-design-patterns"><img src="https://agentmods.dev/badge/skills/ahonn/dotfiles/rust-design-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 77 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,047 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00077 $0.02047
Opus 5 $0.00039 $0.01024
Sonnet 5 $0.00015 $0.00409
Haiku 4.5 $0.00008 $0.00205

Measured yesterday against content hash da8cc58bf1fb, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

rust-design-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/skills/rust-design-patterns/SKILL.md · 316 lines

How it starts

The opening of the file, as written. The whole thing — 316 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Rust Design Patterns

Idioms and patterns for writing idiomatic Rust code. Focus on Rust-specific patterns that leverage ownership, borrowing, and the type system.

Decision Tree

Problem?
├── Borrow checker error?
│   ├── Need to move value from &mut enum → mem::take/replace
│   ├── Need independent field borrows → struct decomposition
│   ├── Tempted to clone? → Check: Rc/Arc? Or refactor ownership?
│   └── Lifetime too short → consider owned types or 'static
│
├── API design?
│   ├── Many constructor params → Builder pattern
│   ├── Accept flexible input → Borrowed types (&str, &[T])
│   ├── Type safety at compile time → Newtype pattern
│   ├── Default values needed → Default trait + struct update syntax
│   └── Resource cleanup needed → RAII guards (Drop trait)
│
├── FFI boundary?
│   ├── Error handling → Integer codes + error description fn
│   ├── String passing → CString/CStr patterns
│   └── Object lifetime → Opaque pointers with explicit free
│
├── Unsafe code?
│   ├── Need unsafe operations → Contain in small modules with safe wrappers
│   └── FFI types → Type consolidation into opaque wrappers
│
└── Performance concern?
    ├── Avoid monomorphization bloat → On-stack dynamic dispatch
    └── Reduce allocations → mem::take instead of clone

Quick Patterns

Borrowed Types (CRITICAL)

Prefer &str over &String, &[T] over &Vec<T>:

// Bad: only accepts &String
fn process(s: &String) { }

// Good: accepts &String, &str, string literals
fn process(s: &str) { }

// Usage: all work with &str
process(&my_string);      // String
process("literal");       // &'static str
process(&my_string[1..5]); // slice

Why: Deref coercion allows &String&str, but not reverse. Using borrowed types accepts more input types.

mem::take Pattern (CRITICAL)

Move owned values out of &mut without clone:

use std::mem;

enum State {
    Active { data: String },
    Inactive,
}

fn deactivate(state: &mut State) {
    if let State::Active { data } = state {
        // Take ownership without clone
        let owned_data = mem::take(data);
        *state = State::Inactive;
        // use owned_data...
    }
}

Read the full file on GitHub · 316 lines

Files

What ships with it

3 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 316 lines · 77 tokens per session scan A da8cc58bf1fb

Subscribe to this mod's changes

rust-design-patterns is a skill published in the GitHub repository ahonn/dotfiles (62 stars, last pushed 4d ago), licensed MIT. It adds 77 tokens to every session and 2,047 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

Other skills, from other repositories

scaffold-rust

Scaffold a complete Rust project with CI/CD, release pipeline, and sr.yaml. Uses cargo as the native build system. Loads on top of scaffold-project (run that first for cross-language standard files). Use when creating a new Rust CLI, library, or workspace, or when the user mentions "new Rust project", "cargo init", or…

urmzd/dotfiles · 102 tokens

scaffold-go

Scaffold a complete Go project with CI/CD, release pipeline, Makefile, sr.yaml, .envrc, and standard files. Uses go toolchain and make as the native build system. Loads on top of scaffold-project (run that first for cross-language standard files). Use when creating a new Go CLI, service, or module, or when the user…

urmzd/dotfiles · 116 tokens

scaffold-node

Scaffold a complete Node/TypeScript project with CI/CD, release pipeline, sr.yaml, .envrc, and standard files. Uses pnpm and biome. Loads on top of scaffold-project (run that first for cross-language standard files). Use when creating a new Node.js app, TypeScript library, or website, or when the user mentions "new…

urmzd/dotfiles · 119 tokens

scaffold-python

Scaffold a complete Python project with CI/CD, release pipeline, justfile, sr.yaml, pyproject.toml, .envrc, and standard files. Uses uv, ruff, and justfile (Python lacks a native task runner like pnpm scripts, so just fills that gap). Loads on top of scaffold-project (run that first for cross-language standard files).…

urmzd/dotfiles · 135 tokens

write-code

Operational tech-stack picks and coding patterns: error handling per language, commit conventions, interface design (Go SDKs), workspace layout, junior-friendly bias. Use when writing or reviewing implementation code and you need a concrete answer for "what tool, pattern, or idiom." Do NOT use for design-tradeoff…

urmzd/dotfiles · 112 tokens

ratatui

Rust terminal UI framework - widgets, components, layouts, events, input handling, and state management for TUI apps.

Mte90/dotfiles · 27 tokens