leonardomso

rust-skills

4
0
# Install this skill:
npx skills add leonardomso/rust-skills

Or install specific skill: npx add-skill https://github.com/leonardomso/rust-skills

# Description

>

# SKILL.md


name: rust-skills
description: >
Comprehensive Rust coding guidelines with 179 rules across 14 categories.
Use when writing, reviewing, or refactoring Rust code. Covers ownership,
error handling, async patterns, API design, memory optimization, performance,
testing, and common anti-patterns. Invoke with /rust-skills.
license: MIT
metadata:
author: leonardomso
version: "1.0.0"
sources:
- Rust API Guidelines
- Rust Performance Book
- ripgrep, tokio, serde, polars codebases


Rust Best Practices

Comprehensive guide for writing high-quality, idiomatic, and highly optimized Rust code. Contains 179 rules across 14 categories, prioritized by impact to guide LLMs in code generation and refactoring.

When to Apply

Reference these guidelines when:
- Writing new Rust functions, structs, or modules
- Implementing error handling or async code
- Designing public APIs for libraries
- Reviewing code for ownership/borrowing issues
- Optimizing memory usage or reducing allocations
- Tuning performance for hot paths
- Refactoring existing Rust code

Rule Categories by Priority

Priority Category Impact Prefix Rules
1 Ownership & Borrowing CRITICAL own- 12
2 Error Handling CRITICAL err- 12
3 Memory Optimization CRITICAL mem- 15
4 API Design HIGH api- 15
5 Async/Await HIGH async- 15
6 Compiler Optimization HIGH opt- 12
7 Naming Conventions MEDIUM name- 16
8 Type Safety MEDIUM type- 10
9 Testing MEDIUM test- 13
10 Documentation MEDIUM doc- 11
11 Performance Patterns MEDIUM perf- 11
12 Project Structure LOW proj- 11
13 Clippy & Linting LOW lint- 11
14 Anti-patterns REFERENCE anti- 15

Quick Reference

1. Ownership & Borrowing (CRITICAL)

2. Error Handling (CRITICAL)

3. Memory Optimization (CRITICAL)

4. API Design (HIGH)

5. Async/Await (HIGH)

6. Compiler Optimization (HIGH)

7. Naming Conventions (MEDIUM)

8. Type Safety (MEDIUM)

9. Testing (MEDIUM)

10. Documentation (MEDIUM)

11. Performance Patterns (MEDIUM)

12. Project Structure (LOW)

13. Clippy & Linting (LOW)

14. Anti-patterns (REFERENCE)


[profile.release]
opt-level = 3
lto = "fat"
codegen-units = 1
panic = "abort"
strip = true

[profile.bench]
inherits = "release"
debug = true
strip = false

[profile.dev]
opt-level = 0
debug = true

[profile.dev.package."*"]
opt-level = 3  # Optimize dependencies in dev

How to Use

This skill provides rule identifiers for quick reference. When generating or reviewing Rust code:

  1. Check relevant category based on task type
  2. Apply rules with matching prefix
  3. Prioritize CRITICAL > HIGH > MEDIUM > LOW
  4. Read rule files in rules/ for detailed examples

Rule Application by Task

Task Primary Categories
New function own-, err-, name-
New struct/API api-, type-, doc-
Async code async-, own-
Error handling err-, api-
Memory optimization mem-, own-, perf-
Performance tuning opt-, mem-, perf-
Code review anti-, lint-

Sources

This skill synthesizes best practices from:
- Rust API Guidelines
- Rust Performance Book
- Rust Design Patterns
- Production codebases: ripgrep, tokio, serde, polars, axum, deno
- Clippy lint documentation
- Community conventions (2024-2025)

# README.md

Rust Skills

179 Rust rules your AI coding agent can use to write better code.

Works with Claude Code, Cursor, Windsurf, Copilot, Codex, Aider, Zed, Amp, Cline, and pretty much any other agent that supports skills.

Install

npx add-skill leonardomso/rust-skills

That's it. The CLI figures out which agents you have and installs the skill to the right place.

How to use it

After installing, just ask your agent:

/rust-skills review this function
/rust-skills is my error handling idiomatic?
/rust-skills check for memory issues

The agent loads the relevant rules and applies them to your code.

What's in here

179 rules split into 14 categories:

Category Rules What it covers
Ownership & Borrowing 12 When to borrow vs clone, Arc/Rc, lifetimes
Error Handling 12 thiserror for libs, anyhow for apps, the ? operator
Memory 15 SmallVec, arenas, avoiding allocations
API Design 15 Builder pattern, newtypes, sealed traits
Async 15 Tokio patterns, channels, spawn_blocking
Optimization 12 LTO, inlining, PGO, SIMD
Naming 16 Following Rust API Guidelines
Type Safety 10 Newtypes, parse don't validate
Testing 13 Proptest, mockall, criterion
Docs 11 Doc examples, intra-doc links
Performance 11 Iterators, entry API, collect patterns
Project Structure 11 Workspaces, module layout
Linting 11 Clippy config, CI setup
Anti-patterns 15 Common mistakes and how to fix them

Each rule has:
- Why it matters
- Bad code example
- Good code example
- Links to official docs when relevant

Manual install

If add-skill doesn't work for your setup, here's how to install manually:

Claude Code Global (applies to all projects):
git clone https://github.com/leonardomso/rust-skills.git ~/.claude/skills/rust-skills
Or just for one project:
git clone https://github.com/leonardomso/rust-skills.git .claude/skills/rust-skills
OpenCode
git clone https://github.com/leonardomso/rust-skills.git .opencode/skills/rust-skills
Cursor
git clone https://github.com/leonardomso/rust-skills.git .cursor/skills/rust-skills
Or just grab the skill file:
curl -o .cursorrules https://raw.githubusercontent.com/leonardomso/rust-skills/master/SKILL.md
Windsurf
mkdir -p .windsurf/rules
curl -o .windsurf/rules/rust-skills.md https://raw.githubusercontent.com/leonardomso/rust-skills/master/SKILL.md
OpenAI Codex
git clone https://github.com/leonardomso/rust-skills.git .codex/skills/rust-skills
Or use the AGENTS.md standard:
curl -o AGENTS.md https://raw.githubusercontent.com/leonardomso/rust-skills/master/SKILL.md
GitHub Copilot
mkdir -p .github
curl -o .github/copilot-instructions.md https://raw.githubusercontent.com/leonardomso/rust-skills/master/SKILL.md
Aider Add to `.aider.conf.yml`:
read: path/to/rust-skills/SKILL.md
Or pass it directly:
aider --read path/to/rust-skills/SKILL.md
Zed
curl -o AGENTS.md https://raw.githubusercontent.com/leonardomso/rust-skills/master/SKILL.md
Amp
git clone https://github.com/leonardomso/rust-skills.git .agents/skills/rust-skills
Cline / Roo Code
mkdir -p .clinerules
curl -o .clinerules/rust-skills.md https://raw.githubusercontent.com/leonardomso/rust-skills/master/SKILL.md
Other agents (AGENTS.md) If your agent supports the [AGENTS.md](https://agents.md) standard:
curl -o AGENTS.md https://raw.githubusercontent.com/leonardomso/rust-skills/master/SKILL.md

All rules

See SKILL.md for the full list with links to each rule file.

Where these rules come from

Contributing

PRs welcome. Just follow the format of existing rules.

License

MIT

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.