Tooluck logoTooluck
SKILL.md

rust-best-practices

Agent skill frommorganlinton/BeautifulRust

Write idiomatic, robust, maintainable Rust. Use this skill whenever you write, review, refactor, debug, or explain Rust code: new crates, modules, functions, structs, traits, error types, async code, unsafe or FFI code, Cargo.toml, tests, or rustdoc. Trigger on any mention of Rust, cargo, crates, .rs files, the borrow checker, lifetimes, traits, clippy, or rustfmt, even when the user does not ask for "best practices" or "idiomatic" code. Synthesized from the Google Rust Style Guide, the Rust API Guidelines, Effective Rust, Rust Design Patterns, and Microsoft's Pragmatic Rust Guidelines.

How to install rust-best-practices

install rust-best-practices
# install the BeautifulRust pack with the skills CLI
npx skills add morganlinton/BeautifulRust

# or add only this skill to Claude Code: copy the folder

skills/rust-best-practices/

# into

~/.claude/skills/rust-best-practices/ (all projects)

.claude/skills/rust-best-practices/ (one project)

skills/rust-best-practices/SKILL.md

MITFull file
1# Rust best practices
2
3Distilled from five Rust style and design guides, with a digest of each in `references/`.
4Where they disagree, this file says which to follow and why.
5
6## 1. Mindset
7
8- **Write Rust-shaped code.** Don't port C++, Java, C#, or Python constructs one-to-one.
9 Model errors with `Result`, resources with ownership and `Drop`, polymorphism with
10 traits and enums, and nullability with `Option`. Inheritance-flavored tricks (`Deref` to
11 a "base" struct, `Manager`/`Factory` types, `throw_if_null` helpers) are smells.
12- **Make invalid states unrepresentable.** Push invariants into types: enums instead of
13 bool flags and "must be X if Y" comments, newtypes for units and IDs, fallible
14 constructors that validate once. Then the compiler enforces what a comment only requests.
15- **Application code is not library code.** Library code (anything with external users)
16 follows the API-design rules below strictly. Application code should favor simplicity
17 and directness: concrete types, `String` or `&str` rather than `impl Into<String>`
18 parameters, `anyhow`-style errors, `Vec` return values, no speculative generality.
19- **Let the tools do the work.** rustfmt owns formatting, clippy owns idiom checks, the
20 compiler owns memory safety. Spend your attention on design.
21
22## 2. Before you hand back code
23
24Run these and fix everything they report:
25
26```bash
27cargo fmt
28cargo clippy --all-targets --all-features -- -D warnings
29cargo test
30…

Excerpt shown under the repository's MIT license.

More skills in BeautifulRust

Keep exploring

Similar skill repositories

Newsletter

Join the Community

Subscribe to our newsletter for the latest news and updates