/effective-rust:effective-rustfrom effective-rust
Provides idiomatic Rust guidance for writing, reviewing, refactoring, and debugging. Activates on .rs files, Cargo.toml, cargo/clippy/rustfmt/rustc/miri commands, and any Rust-related questions.
Ships in effective-rust. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Rust rewards code that leans on the standard library, the type system and the
compiler's lints. Agents writing Rust tend to do the opposite: hand-roll
helpers that already exist in std, clone their way past the borrow checker,
return String errors, sprinkle unwrap() and #[allow], and guess at crate
APIs. Every one of those is a bug or a review comment waiting to happen. This
skill exists to make the idiomatic choice the default one.
Tradeoff: the skill biases toward reading before writing. For a one-line fix in a crate you already understand, use judgment and skip the gates that do not apply.
Precedence: a project's own CLAUDE.md/AGENTS.md, Cargo.toml
[lints], clippy.toml, rustfmt.toml, deny.toml and CI workflows are the
local law. When they disagree with this skill, follow the project.
Before writing any helper, type, trait, macro or algorithm, look for it in this order and stop at the first hit:
std / core / alloc. Search docs.rs/std and the table in
references/already-exists.md. The std version is tested, optimised,
const-friendly and instantly recognisable to reviewers.rg or
ast-grep --lang rust, then read Cargo.toml and cargo tree --depth 1.
A dependency such as itertools, bytes, winnow or tokio often already
provides what you are about to write, and the crate may already have a
private helper for it.cargo info <crate>.
Adding a dependency is a visible decision: check maintenance, licence,
MSRV, transitive size (cargo tree -p <crate>), and copy the project's
default-features = false convention if it uses one. Say in your summary
that you added it and why.Treat "I will just write a quick version" as a signal to run the lookup, not to skip it.
rustc --version and read rust-toolchain.toml, the edition and
rust-version (MSRV) fields. You may only use language and library features
that exist at the MSRV. Do not change edition, MSRV or toolchain channel
without being asked.Cargo.toml (workspace and crate): [lints], [features],
dependencies and their feature flags. Read clippy.toml, rustfmt.toml,
deny.toml, .config/nextest.toml and the CI workflow. They tell you which
commands must pass and which lints are errors.[lints] table? Add the baseline from references/lints.md to the root
Cargo.toml before writing code, tell the user, and fix what clippy then
reports in the code you touch. Those lints enforce half of this skill
(core over std, Self, as _, no unwrap, no allow, documented
unsafe); working without them means relearning it in review.rust-analyzer --version. When the LSP tool is available, use it for
hover, go-to-definition, references and diagnostics instead of guessing
signatures. cargo check is the fallback, not the first resort.bool/Option flags, typestate for protocols and lifecycles.&str, &[T],
&Path). Input you keep, extend or transform: take it by value, so the
caller's existing allocation and its spare capacity do the work; make it
impl Into<T> when callers may hold either form, so an existing T moves
in free and others opt into the conversion at the call site. Output
the caller will reuse: fill &mut Vec<u8>, &mut String or impl Write.
Sequences: return impl Iterator and let the caller collect, count or
stop early. A cost hidden inside a convenient signature is one the caller
can never avoid. See "Who pays" in references/patterns.md.thiserror enum for libraries,
anyhow/eyre with context for binaries. See references/errors.md.dyn Trait when you need heterogeneous
collections, plugin boundaries or smaller binaries.pub in a library, you are designing an API: read
references/api-design.md first.From, TryFrom or FromStr instead of
to_frame(), frame_from(..) or parse_frame(..). Callers get ?,
into() and collect for free, and the compiler finds every conversion
site. Assembling a value from several independent parts is construction,
not conversion: Frame::new(header, payload) or a builder is right there.foo-tokio, foo-serde) or a refactor. Features are global,
additive-only and hard to test in isolation; a crate is an ordinary
dependency with its own tests and docs.pub(super) when a parent needs a child item, pub(crate) only for
genuinely crate-wide items, and pub only for the few items that are the
crate's API, re-exported from lib.rs.macro_rules! is justified for repetition the type system cannot express
(implementing a trait for every integer type). Do not add proc-macro
crates; using derive macros from existing dependencies is fine.? to match on Result,
combinators (map, and_then, ok_or_else, unwrap_or_else) to nested
match, let else and matches! to boilerplate._ => arm hides the next variant's
bug from the compiler.Self instead of the type name inside its impl blocks, and import
traits used only for their methods as use foo::Trait as _;. Both survive
renames and keep names out of scope (clippy use_self,
unused_trait_names).[workspace.dependencies] with
default-features = false, and let each crate enable only the features it
uses (tokio = { workspace = true, features = ["rt", "macros"] }). A
single crate does the same in [dependencies]. Default features pull in
code nobody asked for, and binary size and build time pay for it.core and alloc when the item lives there (core::fmt,
core::error::Error, core::ffi::CStr, alloc::vec::Vec,
alloc::string::String). Reach for std only for OS facilities: fs,
net, thread, env, process, io, SystemTime. It costs nothing in
a std crate and keeps the code usable from no_std users.&CStr, &Path,
Port) and let the caller convert. A &str parameter that runs
CString::new inside hides both an allocation and an error.unwrap(), expect(), panic!, todo! and unimplemented! stay out of
non-test code unless the invariant is locally provable; then write
expect("<why this cannot fail>").#[allow(..)] to make a lint go away. Fix the cause. If it is a
true false positive, use #[expect(lint, reason = "..")] so the attribute
errors when it becomes stale.unsafe is not a tool for fighting the borrow checker or for speed without
a benchmark. Pass the gate in references/unsafe-ffi.md first.pub items the way the crate already does, following
RFC 1574 (summary line, # Examples, # Errors, # Panics, # Safety).cargo check --all-targets # fast; iterate here
cargo clippy --all-targets --all-features # zero new warnings
cargo test # or: cargo nextest run && cargo test --doc
cargo fmt # cargo +nightly fmt if rustfmt.toml uses unstable options
cargo doc --no-deps # when you touched public docs
u16::try_from(70_000) fails or that CString::new rejects interior NULs
tests the standard library, which is already tested. Every test exercises
a behaviour of this crate.cargo fmt and cargo clippy --all-targets run after the last edit, not
only before it. Clippy finds the shape smells this skill lists; fmt keeps
the diff reviewable.--no-default-features and --all-features
for the touched crate (cargo hack --feature-powerset if installed).-p <crate> while iterating, run --workspace before
you finish.no_std crates: check against the target CI uses, for example
cargo check --no-default-features --target thumbv7em-none-eabi.cargo semver-checks if installed and state the
semver impact (patch, minor, breaking) in your summary.Your summary names: dependencies added or removed, public API changes and
their semver impact, every new unsafe block, every #[expect], and any
MSRV or feature implications. These are the things a Rust reviewer looks for
first.
These are gates, not suggestions. Each row names the cheapest source that
prevents the most common mistake for that task. Full URLs live in
references/resources.md.
| Before you... | Read first |
|---|---|
| Write a conversion between your own types | Conversions section of references/patterns.md; Effective Rust Item 5 |
Design or change a pub API in a library | references/api-design.md; Rust API Guidelines checklist; RFC 1105 (API evolution), RFC 344 and 199 (naming); Google Rust Style Guide (traits, naming, #[must_use]); Effective Rust Items 1–13, 22–24 |
| Lay out modules, name files, modules, constructors or accessors | Modules and crates section of references/patterns.md; Google Rust Style Guide (code organisation, naming) |
| Define an error type or choose an error strategy | references/errors.md; Effective Rust Item 4; thiserror and anyhow docs |
| Add a dependency | references/already-exists.md; blessed.rs; the crate's docs.rs page; Effective Rust Items 25–26 |
| Call a crate API you have not used in this session | Its docs.rs page at the version pinned in Cargo.lock. Never guess method names or signatures |
| Write a safe wrapper over C or OS APIs | Boundary types section of references/unsafe-ffi.md |
Write unsafe, FFI, #[repr], raw pointers or transmute | references/unsafe-ffi.md; the Rustonomicon; Unsafe Code Guidelines; then run Miri |
Write async code, spawn tasks, use select!, pick a runtime | references/async.md; Tokio tutorial; "Async: What is blocking?"; tokio::select! cancellation-safety docs |
| Share state across threads, use atomics or locks | std::sync docs; Rust Atomics and Locks; Effective Rust Item 17 |
Reach for clone(), Rc<RefCell<_>> or unsafe to satisfy the borrow checker | Effective Rust Items 14–15; Rust Design Patterns anti-pattern "Clone to satisfy the borrow checker"; ownership section of references/patterns.md |
| Optimise anything | Rust Performance Book; Effective Rust Item 20; a criterion/divan benchmark before and after |
| Write a macro | Effective Rust Item 28; The Little Book of Rust Macros; API Guidelines macros section |
| Shrink a binary or tune a release profile | min-sized-rust; Cargo profiles reference |
| Configure lints in a project that has none | references/lints.md |
| Add or change cargo features, bump a version, publish | Cargo features and SemVer references; Effective Rust Items 21, 26; cargo semver-checks |
| Change edition or MSRV | Edition Guide; RFC 3501 (edition 2024); Cargo rust-version reference |
| Write rustdoc | RFC 1574 (conventions) and RFC 1946 (intra-doc links); rustdoc book "What to include"; API Guidelines documentation section |
| Write tests, benches, fuzzers | references/tooling.md; Effective Rust Item 30; Book ch. 11; proptest, insta, cargo-fuzz books |
| Choose a collection type | std::collections "When should you use which collection?" |
Make a library no_std | Effective Rust Item 33; Embedded Rust Book |
| Fail to fix a compiler error on the first try | rustc --explain E0xxx; the Rust Error Codes Index; RFC 1023 for orphan-rule errors (E0117, E0210) |
| Silence a lint | That lint's page in the Clippy lint list, to learn what it protects against |
Details and snippets in references/patterns.md.
UserId(u64), Port(u16))
with a validating constructor and TryFrom.bon or typed-builder if the project already depends on one.Drop) for anything that must be released or restored.Default derive plus ..Default::default() struct update syntax.impl Into<T>) to keep or extend, take &mut buffers or impl Write to
fill, return impl Iterator to let the caller decide what to materialise
(C-CALLER-CONTROL).mem::take / mem::replace / Option::take to move out of &mut
without cloning.map.entry(k).or_insert_with(..)) instead of get-then-insert.collect::<Result<Vec<_>, _>>() to fail fast
over a sequence.? with From conversions so error plumbing is one character.let else, matches!, if let .. else, let chains (edition 2024) for
shallow control flow.impl Trait in return position to hide iterator and future types.From / TryFrom / FromStr for every one-to-one conversion between
your own types; new and builders for assembling a value from parts.#[non_exhaustive] so the public API can grow.Cow<'_, str> when a function usually borrows but sometimes must own.Arc<str> / Box<str> / Box<[T]> for immutable shared data.std::thread::scope for borrowing across threads without Arc.Arc<Mutex<_>>
for shared mutable state in async code.LazyLock / OnceLock for lazy globals.main: binaries put logic in lib.rs and keep main.rs to
argument parsing and fn main() -> anyhow::Result<()>.core/alloc imports so they stay no_std-friendly.Details and the replacement for each in references/anti-patterns.md.
references/already-exists.md
(split/trim helpers, lazy init, dedup, chunking, retry loops, arg parsing,
JSON, hashing, base64, random).clone() or Rc<RefCell<_>> as the first answer to a borrow error.Result<T, String>, Box<dyn Error> in a library's public API, errors that
lose the source() chain, stringified errors.unwrap() / expect() / panic! on recoverable conditions in library code.as for numeric conversions that can truncate or wrap; use From,
TryFrom, checked_*, saturating_*.String only read, &str turned into
to_owned() on the first line, a fresh Vec returned where a &mut buffer
or an iterator would let the caller reuse what it has, println! inside a
library where impl Write lets the caller pick the sink.&String, &Vec<T>, &Box<T> parameters.bool and Option<bool> parameters, out-parameters, Option<Option<T>>.impl Deref to fake inheritance.#![deny(warnings)] in source (breaks on every toolchain update) and
#[allow(..)] to silence lints.use foo::* outside tests and preludes.static mut, transmute, unsafe without a // SAFETY: comment.lazy_static! / once_cell when the MSRV has std::sync::LazyLock.async_trait when native async fn in traits works (keep it for
dyn Trait).std::fs, std::thread::sleep, CPU loops) and holding a
std::sync::MutexGuard across .await..awaits that should be join!, JoinSet or
buffer_unordered.println!, eprintln! or std::process::exit inside library code.for i in 0..v.len() index loops; collect() into a Vec only to iterate
again._ => arms on enums you own; #[inline] sprinkled without a benchmark.to_c(), c_from_a() or parse_c() functions where From,
TryFrom or FromStr is the whole story.[workspace.dependencies].foo-tokio) would be cleaner.impl; importing a trait by name
when only its methods are used.&str parameters that silently allocate a CString, PathBuf or String
inside; the caller should see the allocation and the error.std:: paths for items that live in core or alloc.pub(crate) on helpers
that only the parent and its children use.macro_rules! for anything a trait or generic can express.std or a dependency rather than this crate.no-std, no-serde).Read the one that matches the task; each is self-contained.
| File | Read when |
|---|---|
references/already-exists.md | About to write a helper, or about to add a dependency |
references/resources.md | You need the URL for any book, guide or doc named in this skill |
references/patterns.md | Implementing types, ownership, control flow, modules |
references/anti-patterns.md | Reviewing code, or unsure whether a construct is idiomatic |
references/errors.md | Defining, converting, reporting or testing errors |
references/api-design.md | Any pub item in a library, semver, features, docs |
references/async.md | tokio, futures, tasks, channels, cancellation, blocking |
references/unsafe-ffi.md | unsafe, raw pointers, #[repr], FFI, Miri |
references/tooling.md | cargo, clippy configuration, tests, benches, fuzzing, coverage |
references/lints.md | The lint baseline to enable in a project without one, with reasons |
evals/async-file-checksums/case.yaml (opens in a new tab)evals/async-file-checksums/files/fileproc/Cargo.toml (opens in a new tab)evals/async-file-checksums/files/fileproc/src/main.rs (opens in a new tab)evals/async-file-checksums/graders/01-no-blocking-io-in-async.md (opens in a new tab)evals/async-file-checksums/graders/02-checksum-off-runtime.md (opens in a new tab)evals/async-file-checksums/graders/03-bounded-concurrency.md (opens in a new tab)evals/async-file-checksums/graders/04-graceful-ctrl-c.md (opens in a new tab)evals/async-file-checksums/graders/05-no-guard-across-await.md (opens in a new tab)evals/async-file-checksums/graders/06-builds-clippy-clean.md (opens in a new tab)evals/async-file-checksums/graders/07-errors-not-unwrapped.md (opens in a new tab)evals/async-file-checksums/place-files.sh (opens in a new tab)evals/async-file-checksums/prompt.md (opens in a new tab)evals/borrow-checker-inventory-refactor/case.yaml (opens in a new tab)evals/borrow-checker-inventory-refactor/files/inventory/Cargo.toml (opens in a new tab)evals/borrow-checker-inventory-refactor/files/inventory/src/lib.rs (opens in a new tab)evals/borrow-checker-inventory-refactor/graders/01-no-clones-in-src.md (opens in a new tab)evals/borrow-checker-inventory-refactor/graders/02-iterators-not-index-loops.md (opens in a new tab)evals/borrow-checker-inventory-refactor/graders/03-retain-and-iter-mut.md (opens in a new tab)evals/borrow-checker-inventory-refactor/graders/04-low-stock-borrows.md (opens in a new tab)evals/borrow-checker-inventory-refactor/graders/05-no-interior-mutability-escape.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub altair-bueno/effective-rust --plugin effective-rustOther plugins' skills for the same job