rust-best-practices

rust-best-practices is a skill for Claude Code from majiayu000/spellbook. It costs 51 tokens per session (610 once invoked), scanned A, original, MIT.

A guide to writing idiomatic Rust code using safe ownership, clear error handling, standard formatting, and compiler-supported design practices.

In plain words
What is it for?
Use it when writing, reviewing, optimizing, or debugging Rust code, including lifetimes, asynchronous code, Cargo, and the borrow checker.
Why use it?
It helps avoid memory-safety bugs, unnecessary copying, unclear errors, and common style problems while working with Rust's ownership system.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Part of the rust-dev plugin — 1 skill shipped together

Good fit Use it when writing, reviewing, optimizing, or debugging Rust code, including lifetimes, asynchronous code, Cargo, and the borrow checker.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/majiayu000/spellbook/rust-best-practices
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.

Any agent
npx skills add majiayu000/spellbook --skill rust-best-practices
Clone the repo
git clone --depth 1 https://github.com/majiayu000/spellbook

Made for: Claude Code.

Or install rust-dev, the plugin that ships this one along with the rest of its 1 skill.

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-best-practices

README.md
[![agentmods](https://agentmods.dev/badge/skills/majiayu000/spellbook/rust-best-practices/github.svg)](https://agentmods.dev/skills/majiayu000/spellbook/rust-best-practices)
Your own site
<a href="https://agentmods.dev/skills/majiayu000/spellbook/rust-best-practices"><img src="https://agentmods.dev/badge/skills/majiayu000/spellbook/rust-best-practices/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for rust-best-practices

Your own site · 80×15
<a href="https://agentmods.dev/skills/majiayu000/spellbook/rust-best-practices"><img src="https://agentmods.dev/badge/skills/majiayu000/spellbook/rust-best-practices.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 51 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 610 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00051 $0.00610
Opus 5 $0.00026 $0.00305
Sonnet 5 $0.00010 $0.00122
Haiku 4.5 $0.00005 $0.00061

Measured 6d ago against content hash 77402ffc4879, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

Grade A, and why

rust-best-practices 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 6d ago.

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.

plugins/rust-dev/skills/rust-best-practices.SKILL.md · 62 lines

How it starts

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

Rust Best Practices Assistant

Core Principles

  • Prefer safe Rust; use unsafe only when absolutely necessary and well-documented
  • Leverage the type system to prevent bugs at compile time
  • Use Result<T, E> for error handling, avoid panic! in library code
  • Make illegal states unrepresentable through proper type design

Code Style

  • Format all code with rustfmt
  • Follow all clippy suggestions (run with cargo clippy -- -W clippy::pedantic)
  • Use snake_case for variables and functions
  • Use CamelCase for types and traits
  • Use SCREAMING_SNAKE_CASE for constants

Memory & Ownership

  • Prefer borrowing (&T, &mut T) over ownership when possible
  • Use Cow<str> for strings that might be borrowed or owned
  • Avoid unnecessary .clone() - consider borrowing or restructuring
  • Use Arc<T> for shared ownership across threads, Rc<T> for single-threaded

Error Handling

  • Use thiserror for defining library error types
  • Use anyhow for application-level error handling
  • Provide meaningful, actionable error messages
  • Use ? operator for error propagation

Performance

  • Avoid unnecessary heap allocations
  • Prefer iterators over manual loops (zero-cost abstraction)
  • Use &str instead of String for function parameters when possible
  • Consider using SmallVec for small, stack-allocated vectors

Async Rust

  • Use tokio as the async runtime for most applications
  • Prefer async fn over manual Future implementations
  • Avoid blocking operations in async contexts
  • Use tokio::spawn for concurrent tasks

Testing

  • Write unit tests in the same file using #[cfg(test)] module
  • Use #[should_panic] for testing panic behavior
  • Use proptest or quickcheck for property-based testing
  • Aim for meaningful test coverage, not just line coverage

Common Patterns

  • Use the builder pattern for complex object construction
  • Use From and Into traits for type conversions
  • Implement Default when a sensible default exists
  • Use Option<T> instead of sentinel values

Read the full file on GitHub · 62 lines

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. 6d ago First seen · 62 lines · 51 tokens per session scan A 77402ffc4879

Subscribe to this mod's changes

rust-best-practices is a skill published in the GitHub repository majiayu000/spellbook (277 stars, last pushed yesterday), licensed MIT. It adds 51 tokens to every session and 610 once invoked, about $0.0003 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

Rust Patterns

Use this skill when writing Rust crates/services and you want reliable patterns for error handling, module structure, ownership boundaries, and maintainable APIs.

AmariahAK/atlarix-skills · 2 tokens

python-release

Handle Python SDK release, build, bump, packaging metadata, PyPI client pin, uv.lock, nox/build workflow, and publish verification changes. Use for Python release process work or dependency pin bumps; do not use for ordinary Python feature implementation.

ComposioHQ/composio · 53 tokens

Agent Browser Automation

Fast Rust-based headless browser automation CLI with Node.js fallback for AI agents, featuring navigation, clicking, typing, snapshots, and structured commands optimized for agent workflows.

PramodDutta/qaskills · 37 tokens

pneuma-session

Instructions for renaming an active Pneuma session and replacing its default preview with a useful title and summary. A Pneuma session is one work area inside a larger project.

pandazki/pneuma-skills · 127 tokens

architecture-audit

Systematic architecture audit and refactoring methodology for Rust + TypeScript codebases. Use when performing refactoring, cleanup, unification, code review, dead code removal, module reorganization, or tech debt elimination. Ensures no naming confusion, semantic overloading, hidden defaults, duplicate logic, or…

org2AI/ORG2 · 70 tokens

dcg

Destructive Command Guard - High-performance Rust hook for Claude Code that blocks dangerous commands before execution. SIMD-accelerated, modular pack system, whitelist-first architecture. Essential safety layer for agent workflows.

Dicklesworthstone/destructive_command_guard · 42 tokens