Agent skill

Rust Best Practices

by majiayu000 in majiayu000/spellbook

A skill your agent uses when writing, modifying, or reviewing Rust code.

MITAuto-check passedBackend & APIs

Install Rust Best Practices

skills CLI
$ npx skills add majiayu000/spellbook --skill rust-best-practices -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install majiayu000/spellbook rust-best-practices --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/majiayu000/spellbook.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/rust-best-practices .claude/skills/rust-best-practices && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
rust-best-practices
GitHub stars
287
Token cost
~955 tokens
SKILL.md length
118 words
Files
2 (incl. references)
Skills in repo
97
Repo updated
First seen
Licence
MIT

At a glance

A skill your agent uses when writing, modifying, or reviewing Rust code.

  • Works in 5 steps: Leverage the type system — Use types to… → Embrace ownership — Work with the borrow… → Explicit over implicit — Be clear about… → …
  • Reviewing Rust code
  • SKILL.md covers Core Principles, Error Handling, API Design and References
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Rust Best Practices is an agent skill from majiayu000/spellbook. Use when writing, modifying, or reviewing Rust code. ALWAYS invoke before Rust edits; covers Microsoft Pragmatic Rust guidance for error handling, API design, performance, and idiomatic patterns.

Its SKILL.md is about 960 tokens, which your agent loads only when the skill is triggered. The skill folder holds 2 other files, including reference files (for example `references/advanced.md`).

It sits in Backend & APIs, covering API design. It works with Rust. The repository describes itself as: Cross-runtime skills for Claude Code, Codex, and multi-agent workflows. The licence is MIT.

When your agent uses it

  • Reviewing Rust code
  • Tasks that involve API design

Example prompts

  • “/rust-best-practices”

Workflow steps

5 steps, taken from the first numbered list in SKILL.md.

  1. Leverage the type system — Use types to make invalid states unrepresentable
  2. Embrace ownership — Work with the borrow checker, not against it
  3. Explicit over implicit — Be clear about fallibility, mutability, and lifetimes
  4. Zero-cost abstractions — Use iterators, generics, and traits without runtime cost
  5. Fail fast, recover gracefully — Validate early, handle errors explicitly

What it can do on your machine

Read from SKILL.md and the folder at commit ed52af7. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are rust).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • microsoft.github.io
    • rust-lang.github.io
    • doc.rust-lang.org

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Rust Best Practices loads about 955 tokens when it runs, and up to ~1.8k if it reads all its reference files. Until then it costs about 54 tokens; SKILL.md has 118 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~54
When it runs · the whole SKILL.md, loaded when a task matches
~955
With references · SKILL.md plus every file in references/, read only if the agent opens them
~1.8k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from majiayu000/spellbook at commit ed52af7, republished under its MIT licence (© majiayu000). 118 words, ~955 tokens.

Download SKILL.mdSave it as .claude/skills/rust-best-practices/SKILL.md (or your agent's skills folder). This skill also uses 1 other file; get the full folder from GitHub.
name
rust-best-practices
description
Use when writing, modifying, or reviewing Rust code. ALWAYS invoke before Rust edits; covers Microsoft Pragmatic Rust guidance for error handling, API design, performance, and idiomatic patterns.

Rust Best Practices

Based on Microsoft Pragmatic Rust Guidelines and Rust community standards.

Core Principles

  1. Leverage the type system — Use types to make invalid states unrepresentable
  2. Embrace ownership — Work with the borrow checker, not against it
  3. Explicit over implicit — Be clear about fallibility, mutability, and lifetimes
  4. Zero-cost abstractions — Use iterators, generics, and traits without runtime cost
  5. Fail fast, recover gracefully — Validate early, handle errors explicitly

Error Handling

Use thiserror for Libraries
rust
use thiserror::Error;

#[derive(Error, Debug)]
pub enum MyError {
    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),
    #[error("Parse error at line {line}: {message}")]
    Parse { line: usize, message: String },
    #[error("Not found: {0}")]
    NotFound(String),
}
Use anyhow for Applications
rust
use anyhow::{Context, Result};

fn main() -> Result<()> {
    let config = load_config()
        .context("Failed to load configuration")?;
    run_app(config)?;
    Ok(())
}
Never Panic in Libraries
rust
// ❌ BAD
pub fn get_item(index: usize) -> &Item {
    &self.items[index]  // Panics on out-of-bounds
}

// ✅ GOOD
pub fn get_item(&self, index: usize) -> Option<&Item> {
    self.items.get(index)
}

// ✅ GOOD - when you need Result
pub fn get_item(&self, index: usize) -> Result<&Item, Error> {
    self.items.get(index).ok_or(Error::NotFound(index))
}

API Design

Use Builder Pattern for Complex Configs
rust
pub struct Client {
    url: String,
    timeout: Duration,
    retries: u32,
}

impl Client {
    pub fn builder(url: impl Into<String>) -> ClientBuilder {
        ClientBuilder {
            url: url.into(),
            timeout: Duration::from_secs(30),
            retries: 3,
        }
    }
}

pub struct ClientBuilder {
    url: String,
    timeout: Duration,
    retries: u32,
}

impl ClientBuilder {
    pub fn timeout(mut self, timeout: Duration) -> Self {
        self.timeout = timeout;
        self
    }

    pub fn retries(mut self, retries: u32) -> Self {
        self.retries = retries;
        self
    }

    pub fn build(self) -> Client {
        Client {
            url: self.url,
            timeout: self.timeout,
            retries: self.retries,
        }
    }
}
Use Newtype Pattern
rust
// ❌ BAD - primitive obsession
fn create_user(name: String, email: String, age: u32) -> User { ... }

// ✅ GOOD - newtype wrappers
pub struct Username(String);
pub struct Email(String);
pub struct Age(u32);

impl Email {
    pub fn new(email: impl Into<String>) -> Result<Self, ValidationError> {
        let email = email.into();
        if email.contains('@') {
            Ok(Self(email))
        } else {
            Err(ValidationError::InvalidEmail)
        }
    }
}

fn create_user(name: Username, email: Email, age: Age) -> User { ... }
Accept impl Trait for Flexibility
rust
// ❌ BAD - overly specific
pub fn process(items: Vec<String>) { ... }

// ✅ GOOD - accept any iterable
pub fn process(items: impl IntoIterator<Item = impl AsRef<str>>) {
    for item in items {
        println!("{}", item.as_ref());
    }
}

References

© majiayu000, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 1 other file (references) in skills/rust-best-practices of majiayu000/spellbook.

  • SKILL.md
  • references/advanced.md

Open the folder on GitHubat commit ed52af7

Compare with similar skills

Rust Best Practices next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Rust Best Practices compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Rust Best Practices this skillmajiayu000/spellbook287—~955Automated safety check: PassMIT
API Designaxone-protocol/contracts123—~1.1kAutomated safety check: PassBSD-3-Clause
Rust ConventionsGoldziher/ai-rulez159—~746Automated safety check: PassMIT
Rust Trait API Designhashgraph-online/awesome-codex-plugins1.3k—~929Automated safety check: PassMIT
Rust SkillsJMBeresford/retrom2.1k1 repos~9.5kAutomated safety check: PassMIT
Rust Skillsnoh-rs/nohrs156—~5.3kAutomated safety check: PassMIT

Similar skills

  • API Design

    axone-protocol/contracts

    Best practices for designing CosmWasm smart contract APIs. An agent skill from axone-protocol/contracts.

    123 GitHub stars~1.1k tokensUpdated yesterday
    Backend & APIsAuto-check passed
  • Rust Conventions

    Goldziher/ai-rulez

    Rust code conventions covering edition 2024, cargo fmt/clippy, Result-based error handling, unsafe discipline, async with tokio, API-guideline naming, trait implementations, benchmarking, and…

    159 GitHub stars~746 tokensUpdated today
    Backend & APIsAuto-check passed
  • Rust Trait API Design

    hashgraph-online/awesome-codex-plugins

    Design and review Rust trait APIs, generic bounds, dispatch models, and conversion contracts for clear public interfaces.

    1.3k GitHub stars~929 tokensUpdated yesterday
    Backend & APIsAuto-check passed
  • Rust Skills

    JMBeresford/retrom

    Comprehensive Rust coding guidelines with 265 rules across 26 categories.

    2.1k GitHub starsUsed in 1 repo~9.5k tokens
    DevelopmentAuto-check passed
  • Rust Skills

    noh-rs/nohrs

    Comprehensive Rust coding guidelines with 179 rules across 14 categories.

    156 GitHub stars~5.3k tokensUpdated 9 days ago
    DevelopmentAuto-check passed
  • Code Quality

    static-web-server/static-web-server

    Review or self-check a change to the Static Web Server (SWS) project before it is called done — correctness, invariants, API design, concurrency, maintainability, and an SWS-specific review checklist.

    2.4k GitHub stars~1.1k tokensUpdated yesterday
    DevelopmentAuto-check passed

More from majiayu000/spellbook

All 97 skills in this repo
  • Skill Ecosystem Doctor

    majiayu000/spellbook

    Audits and repairs how coding-agent Skills are owned, copied and exposed across runtimes, from canonical sources to quarantine and retirement.

    287 GitHub stars~3k tokensUpdated 2 days ago
    Auto-check passed
  • AGENTS.md Scaffold

    majiayu000/spellbook

    Scans a repository for real evidence and proposes, or on request writes, a small stack of root and scoped AGENTS.md files with validation commands and generated-file boundaries.

    287 GitHub stars~1.5k tokensUpdated 2 days ago
    Auto-check passed
  • Product Demo Builder

    majiayu000/spellbook

    Plans, produces or diagnoses evidence-backed product demo videos: script, capture plan, pacing checks and verified final media built on real product behavior.

    287 GitHub stars~3.3k tokensUpdated 2 days ago
    Auto-check passed
  • Flowguard Task Guard

    majiayu000/spellbook

    Single entry point that routes long or ambiguous agent tasks, checks live state, bounds autonomous loops and leaves a resumable handoff.

    287 GitHub stars~2.1k tokensUpdated 2 days ago
    Auto-check passed
  • npm Supply Chain Check

    majiayu000/spellbook

    Scans a repository, its lockfiles and node_modules for known malicious npm package versions and install-time indicators, using a read-only Python scanner.

    287 GitHub stars~1.5k tokensUpdated 2 days ago
    Auto-check passed
  • Product Manager Toolkit

    majiayu000/spellbook

    Product management helpers: a RICE scoring script, an interview transcript analyzer and PRD templates for prioritizing features, synthesizing research and writing requirements.

    287 GitHub stars~2.2k tokensUpdated 2 days ago
    Auto-check passed

Works with

Categories

Questions about Rust Best Practices

What does Rust Best Practices do?

A skill your agent uses when writing, modifying, or reviewing Rust code. Rust Best Practices is an agent skill from majiayu000/spellbook. Use when writing, modifying, or reviewing Rust code.

When should I use Rust Best Practices?

Rust Best Practices fits situations like: reviewing Rust code; tasks that involve API design.

How do I install Rust Best Practices in Claude Code?

Run `npx skills add majiayu000/spellbook --skill rust-best-practices -a claude-code`. Or copy the skill folder (skills/rust-best-practices in majiayu000/spellbook) into .claude/skills/rust-best-practices in your project. Claude Code loads it when a task matches its description.

How do I install Rust Best Practices in Codex?

Run `npx skills add majiayu000/spellbook --skill rust-best-practices -a codex`. Or copy the skill folder (skills/rust-best-practices in majiayu000/spellbook) into .agents/skills/rust-best-practices in your project. Codex loads it when a task matches its description.

Can I use Rust Best Practices in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add majiayu000/spellbook --skill rust-best-practices -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/rust-best-practices, .gemini/skills/rust-best-practices, .github/skills/rust-best-practices and .opencode/skills/rust-best-practices in your project.

What does Rust Best Practices need to run?

SKILL.md names no scripts, command-line tools or credentials: Rust Best Practices is instructions for the agent only.

Does Rust Best Practices access the network?

SKILL.md names 3 domains. As links in the text: microsoft.github.io, rust-lang.github.io and doc.rust-lang.org. This is read from the text; nothing was executed.

Is Rust Best Practices safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Rust Best Practices use?

Rust Best Practices is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Rust Best Practices use?

About 955 tokens (SKILL.md is roughly 3.8k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 833 tokens, read only when the agent opens those files.

What are the alternatives to Rust Best Practices?

Skills that share tags, products or a category with Rust Best Practices: API Design (axone-protocol/contracts, 123 stars), Rust Conventions (Goldziher/ai-rulez, 159 stars), Rust Trait API Design (hashgraph-online/awesome-codex-plugins, 1.3k stars) and Rust Skills (JMBeresford/retrom, 2.1k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Rust Best Practices?

majiayu000 (a GitHub user) maintains it in majiayu000/spellbook, which has 287 GitHub stars. The repository holds 97 skills in this directory. The repository was last updated on October 8, 2026.

Source: majiayu000/spellbook on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.