Claude-skill-registry rust-skills

install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/other/other/rust-skills" ~/.claude/skills/majiayu000-claude-skill-registry-rust-skills && rm -rf "$T"
manifest: skills/other/other/rust-skills/SKILL.md
source content

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

PriorityCategoryImpactPrefixRules
1Ownership & BorrowingCRITICAL
own-
12
2Error HandlingCRITICAL
err-
12
3Memory OptimizationCRITICAL
mem-
15
4API DesignHIGH
api-
15
5Async/AwaitHIGH
async-
15
6Compiler OptimizationHIGH
opt-
12
7Naming ConventionsMEDIUM
name-
16
8Type SafetyMEDIUM
type-
10
9TestingMEDIUM
test-
13
10DocumentationMEDIUM
doc-
11
11Performance PatternsMEDIUM
perf-
11
12Project StructureLOW
proj-
11
13Clippy & LintingLOW
lint-
11
14Anti-patternsREFERENCE
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)


Recommended Cargo.toml Settings

Standalone project

[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

Workspace

[workspace]
members = ["crates/*"]
resolver = "2"

[workspace.package]
edition = "2024"
rust-version = "1.85"
license = "MIT"

[workspace.dependencies]
# Pin shared dependencies here
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
thiserror = "2"
anyhow = "1"

[workspace.lints.rust]
unsafe_code = "forbid"

[workspace.lints.clippy]
correctness = { level = "deny", priority = -1 }
suspicious = { level = "warn", priority = -1 }
style = { level = "warn", priority = -1 }
complexity = { level = "warn", priority = -1 }
perf = { level = "warn", priority = -1 }
pedantic = { level = "warn", priority = -1 }

[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

Member crates inherit from the workspace:

[package]
name = "my-crate"
version = "0.1.0"
edition.workspace = true
rust-version.workspace = true
license.workspace = true

[dependencies]
tokio = { workspace = true }
serde = { workspace = true }

[lints]
workspace = true

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

TaskPrimary 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: