rust-skills

179 Rust coding rules across 14 categories, prioritized by impact for writing idiomatic, optimized, and maintainable code. Covers critical foundations: ownership and borrowing, error handling, memory optimization, and API design with detailed rules and examples Includes high-priority async/await patterns, compiler optimization techniques, and performance tuning strategies for production systems Provides medium-priority guidance on naming conventions, type safety, testing, documentation, and project structure References anti-patterns and common pitfalls to avoid, plus recommended Cargo.toml settings for release builds Organized by prefix (e.g., own- , err- , async- ) for quick lookup during code generation and review workflows

INSTALLATION
npx skills add https://github.com/leonardomso/rust-skills --skill rust-skills
Run in your project or agent environment. Adjust flags if your CLI version differs.

SKILL.md

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)

  • api-must-use - Add #[must_use] to Result returning functions

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

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

  • Check relevant category based on task type
  • Apply rules with matching prefix
  • Prioritize CRITICAL > HIGH > MEDIUM > LOW
  • 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:

  • Production codebases: ripgrep, tokio, serde, polars, axum, deno
  • Clippy lint documentation
  • Community conventions (2024-2025)
BrowserAct

Let your agent run on any real-world website

Bypass CAPTCHA & anti-bot for free. Start local, scale to cloud.

Explore BrowserAct Skills →

Stop writing automation&scrapers

Install the CLI. Run your first Skill in 30 seconds. Scale when you're ready.

Start free
free · no credit card