From rust-best-practices
Apply idiomatic Rust engineering guidance when Codex writes, reviews, refactors, or explains Rust code. Use this skill for .rs files, Cargo workspaces, new Rust projects, public API design, ownership and borrowing decisions, error handling, Clippy/rustfmt setup, testing strategy, documentation, performance-sensitive code, unsafe or thread-safety review, and readability or architecture feedback.
How this skill is triggered — by the user, by Claude, or both
Slash command
/rust-best-practices:rust-best-practicesThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Use this skill to write Rust code that is readable, explicit, testable,
Use this skill to write Rust code that is readable, explicit, testable, performant by design, and aligned with the Rust ecosystem. Prefer the project's existing conventions first; when the project is new or has no stronger rule, apply the guidance in this skill.
Cargo.toml, crate type, workspace
layout, public API boundaries, feature flags, existing lint config,
rustfmt.toml, tests, docs, and dependency policy.references/review-checklist.md for PR review, audits, or final checks.references/tooling-lints.md for cargo fmt, Clippy, rustdoc lints,
lint configuration, CI commands, and profiling tools.references/ownership-performance.md for borrowing, cloning, allocation,
iterators, dispatch, stack/heap choices, pointers, and shared state.references/api-design.md for public APIs, naming, traits, constructors,
feature flags, type safety, type-state, and future compatibility.references/errors-testing-docs.md for Result, panics, error crates,
async error bounds, tests, doc tests, snapshots, comments, and rustdoc.references/readability-style-architecture.md for file layout, imports,
naming, control flow, helper functions, dependency boundaries, and
maintainable project structure.cargo fmt --checkcargo clippy --all-targets --all-features --locked -- -D warningscargo test --all-targets --all-features --locked
Adjust flags when features are mutually exclusive, the project has no
lockfile, slow tests require opt-in, or the repository documents a custom
just, make, or xtask command.&str over
String, &[T] over Vec<T>, &Path over PathBuf, and Option<&T> over
&Option<T>..clone() as a design decision. Do not clone just to appease the borrow
checker.Vec or String allocations when iterators, slices,
borrowed views, or lazy fallback closures are enough.Result<T, E> for expected failure. Use Option<T> only when absence
has no meaningful error detail.panic!, unwrap, and expect for tests, examples with hidden setup,
unreachable invariants, or programmer errors with precise context.anyhow-style errors mainly at binary,
CLI, application, prototype, or test-helper boundaries.? for propagation when it preserves useful context. Add context at IO,
parsing, network, task, or user-facing boundaries.# Errors, # Panics, and # Safety
sections where relevant.snake_case values,
UpperCamelCase types, SCREAMING_SNAKE_CASE constants, and meaningful
as_/to_/into_ conversions.Debug, Clone,
Copy, Eq, Hash, Default, Display, Error, From, TryFrom,
AsRef, and AsMut.bool, Option, String,
or primitive parameters.? instead of unwrap unless the unwrap is the point of the example.#[expect(clippy::lint_name)] with a short reason so stale suppressions are
caught later.restriction, pedantic, or
nursery wholesale without project agreement; apply strict lints selectively.#![deny(warnings)] in reusable libraries. Prefer CI flags
or explicit lint configuration to avoid surprise breakage from future compiler
warnings.db, ctx, acc, idx, res, or it.When reviewing Rust code, lead with actionable findings ordered by severity. For each finding, include the file/line, impact, violated Rust principle or local convention, and a practical fix. Then list validation commands and remaining test or API risks.
When writing or refactoring Rust code, briefly state the local convention followed and the validation performed. Do not claim performance wins unless measured or the change removes an obvious allocation or clone in ordinary code.
Fetches up-to-date documentation from Context7 for libraries and frameworks like React, Next.js, Prisma. Use for setup questions, API references, and code examples.
Provides a checklist for code reviews covering functionality, security, performance, maintainability, tests, and quality. Use for pull requests, audits, team standards, and developer training.
npx claudepluginhub tailrocks/tailrocks-marketplace --plugin rust-best-practices