rust-best-practices
Development guidance for writing idiomatic Rust. Use when: (1) writing new Rust functions or modules, (2) choosing between borrowing, cloning, or ownership patterns, (3) implementing error handling with Result types, (4) optimizing Rust code for performance, (5) configuring clippy and linting for a project, (6) deciding between static and dynamic dispatch, (7) writing documentation or doc tests.
Install via CLI (Recommended)
clawhub install openclaw/skills/skills/anderskev/rust-best-practicesRust Best Practices
Guidance for writing idiomatic, performant, and safe Rust code. This is a development skill, not a review skill -- use it when building, not reviewing.
Quick Reference
| Topic | Key Rule | Reference |
|---|---|---|
| Ownership | Borrow by default, clone only when you need a separate owned copy | references/coding-idioms.md |
| Clippy | Run cargo clippy -- -D warnings on every commit; configure workspace lints | references/clippy-config.md |
| Performance | Don't guess, measure. Profile with --release first | references/performance.md |
| Generics | Static dispatch by default, dynamic dispatch when you need mixed types | references/generics-dispatch.md |
| Type State | Encode state in the type system when invalid operations should be compile errors | references/type-state-pattern.md |
| Documentation | // for why, /// for what and how, //! for module/crate purpose | references/documentation.md |
| Pointers | Choose pointer types based on ownership needs and threading model | references/pointer-types.md |
| API Design | Unsurprising, flexible, obvious, constrained -- encode invariants in types | references/api-design.md |
| Ecosystem | Evaluate crates, pick error handling strategy, stay current | references/ecosystem-patterns.md |
Gates
Short sequences with pass conditions before claiming outcomes that need evidence (not an internal “I checked”).
Clippy clean
- From the workspace root (or with
-p <crate>), run:cargo clippy --all-targets --all-features -- -D warnings. - Pass: exit status is
0and the invocation finishes without Clippy-deny failures.
Performance claim
- Build with
cargo build --release(or your benchmark harness) under the same profile you ship or measure. - Capture a before and after number from the same tool and metric (name both), e.g. Criterion
ns/iter,heaptrackallocations, or a flamegraph path on disk. - Pass: you can cite both measurements, or you explicitly state that only correctness or readability changed and you are not claiming a performance delta.
Docs for symbols you changed
- Run
cargo doc --no-depsfor the crate you edited (add-p <crate>in workspaces). - Pass: the doc build succeeds; if
# applies, there are no new missing-doc errors for those symbols.
Coding Idioms
Metadata
Not sure this is the right skill?
Describe what you want to build — we'll match you to the best skill from 16,000+ options.
Find the right skillPaste this into your clawhub.json to enable this plugin.
{
"plugins": {
"official-anderskev-rust-best-practices": {
"enabled": true,
"auto_update": true
}
}
}Related Skills
tutorial-docs
Tutorial patterns for documentation - learning-oriented guides that teach through guided doing
fetch-pr-feedback
Fetch review comments from a PR and evaluate with receive-feedback skill
swift-testing-code-review
Reviews Swift Testing code for proper use of
rust-testing-code-review
Reviews Rust test code for unit test patterns, integration test structure, async testing, mocking approaches, and property-based testing. Covers Rust 2024 edition changes including async fn in traits for mocks,
explanation-docs
Explanation documentation patterns for understanding-oriented content - conceptual guides that explain why things work the way they do