rust-best-practices
БесплатноБез исполняемых скриптовНе проверенDevelopment guidance for writing idiomatic, performant, and safe Rust. Use when writing new Rust modules, designing library APIs, configuring Cargo workspace…
от existential-birds★ 92 звезды на GitHubОб этом скилле
Rust 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 |
|---|---|---|
| Idioms & Edition 2024 | LazyLock/OnceLock, Edition 2024 rules, drop guards, extension traits, index pointers, preludes |
references/coding-idioms.md |
| Clippy | Run cargo clippy -- -D warnings; set priority = -1 on lint groups in [workspace.lints.clippy] |
references/clippy-config.md |
| Performance | Profile --release; watch monomorphization budgets, cache-line alignment, std::hint::black_box |
references/performance.md |
| Generics & Dispatch | Edition 2024 RPIT + use<>, AFIT vs async-trait, variance, dyn compatibility, blanket impls |
references/generics-dispatch.md |
| Documentation | /// sections, nextest --doc caveat, #[diagnostic::on_unimplemented], doc lints |
references/documentation.md |
| API Design | Unsurprising, flexible, obvious, constrained — hidden contracts, sealed traits, fallible close() |
references/api-design.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 & Edition 2024
Borrow by default, prefer std::sync::LazyLock / OnceLock (stable since 1.80) over once_cell / lazy_static, and watch Edition 2024 changes (gen reserved keyword, if let / tail temporary drop order, ! fallback). For scoped state changes, use drop guards (let _guard = ..., never let _ = ...) with mem::replace or scopeguard::defer!. Add methods to foreign types via extension traits, prefer index pointers (slotmap::DefaultKey) for cyclic graphs without unsafe, and curate a lean crate prelude (additions are semver-minor per RFC 1105). See references/coding-idioms.md.
Error Handling & Crate Hygiene
- Error crates: Use
thiserrorin libraries (structured enums callers can match on),anyhowin binaries/CLIs (ergonomic context chaining), andeyrewhen custom error reporters are needed. Never exposeanyhow::Errorin a library's public API. - Auditing: Run
cargo-denyin CI for licenses, advisories, and duplicate bans; usecargo-machete(works on stable) orcargo-udeps(nightly) to prune unused dependencies.
Cargo Feature & Workspace Pitfalls
- Use
dep:syntax (Rust 1.60+) for optional dependencies (json = ["dep:serde_json"]) so dependency names do not leak into your public feature namespace. - Keep features additive: Cargo takes the union of all enabled features across the dependency graph; verify combinations compile with
cargo hack check --feature-powerset --no-dev-depsand verify MSRV lower bounds withcargo +nightly update -Z minimal-versions && cargo +nightly check. [target.'cfg(feature = "...")'.dependencies]is silently ignored — dependency resolution runs before features are evaluated; useoptional = true+[features]instead.- Workspace
pathvs crates.ioversionidentity: Depending on a sibling viapath = "../foo"without a publishedversioncan yield distinctFootypes when downstream consumers resolvefoofrom crates.io; specify{ path = "../foo", version = "..." }for published workspaces. - Compile-time overrides: Set
[profile.dev.package.<slow-dep>] opt-level = 3(oropt-level = 3on heavy proc-macro/crypto deps) to keep debug test builds fast.
Clippy Discipline
Run cargo clippy --all-targets --all-features -- -D warnings on every commit. Configure workspace lints in Cargo.toml with negative priorities on lint groups (priority = -1) so individual lints override them, and use #[expect(clippy::lint)] (not #[allow]) as the standard fo
Установить rust-best-practices в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл rust-best-practices?
Development guidance for writing idiomatic, performant, and safe Rust. Use when writing new Rust modules, designing library APIs, configuring Cargo workspace lints and features, optimizing monomorphization or cache alignment, or migrating to Rust Edition 2024.
Как установить скилл rust-best-practices?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл rust-best-practices запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic