/rust:rustfrom rust
Guides Rust development with conventions, idioms, error handling, concurrency (threads/rayon/Tokio), cargo/clippy/rustfmt toolchain, and rustdoc. Activates for any Rust code task.
Ships in 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.
Lean on the type system and the borrow checker. They are the design surface, not an obstacle. When the compiler rejects
code, the ownership model is wrong — restructure who owns and who borrows rather than reaching for .clone(), Rc, or
unsafe to silence it. Make illegal states unrepresentable: encode invariants in types so the wrong code fails to
compile instead of failing at runtime. A fight with the borrow checker is a design review the compiler is giving you for
free.
Read the reference before doing focused work in its area; SKILL.md alone is sufficient for routine code.
${CLAUDE_SKILL_DIR}/references/idioms.md borrowing/ownership restructuring,
impl Trait vs generics vs dyn, iterator adapters, match/if let/let else, newtype and builder patterns,
From/Into/TryFrom, the as_/to_/into_ cost cheat-table${CLAUDE_SKILL_DIR}/references/errors.md Result/Option/?, thiserror enum templates,
anyhow .context(), the panic/unwrap/expect policy, error-type design (Display/Error/Send/Sync)${CLAUDE_SKILL_DIR}/references/anti-patterns.md AI-produced anti-patterns mapped to the Clippy
lints that catch them, with the idiomatic fix for each${CLAUDE_SKILL_DIR}/references/api-guidelines.md the Rust API Guidelines C-* checklist, RFC 430
naming, #[non_exhaustive], #[must_use], common-trait derives, sealed traits, builders${CLAUDE_SKILL_DIR}/references/parallelism.md threads, scoped threads, rayon, Send/Sync,
channels, shared state (Arc/Mutex) — the CPU-bound multicore path${CLAUDE_SKILL_DIR}/references/async.md the Future/executor model, Tokio, the compiler-invisible
footgun checklist (blocking in async, holding !Send across .await), "do you even need async?"${CLAUDE_SKILL_DIR}/references/structure.md mod.rs-free layout, cargo workspaces, the
[lints]/[workspace.lints] table, profiles, features, MSRV${CLAUDE_SKILL_DIR}/references/toolchain.md the fmt/clippy/nextest/deny verification gates,
rust-analyzer configuration, recommended compiler and Clippy lint sets${CLAUDE_SKILL_DIR}/references/edition-2024.md Rust 2024 edition specifics and migration via
cargo fix --edition${CLAUDE_SKILL_DIR}/references/documentation.md rustdoc conventions, doctests, missing_docs,
intra-doc links, semver-checksUpperCamelCase for types/traits/enum variants, snake_case for functions/methods/modules,
SCREAMING_SNAKE_CASE for consts/statics.UpperCamelCase (Uuid, Stdin, not UUID, StdIn); lower-cased in snake_case.get_ prefix: fn first(&self) -> &First, not fn get_first. Use get only when one obvious value
is gotten (e.g. Cell::get).as_ = free borrow-to-borrow view; to_ = expensive
(allocates or computes); into_ = consuming, ownership transfer.iter (&T), iter_mut (&mut T), into_iter (T); the iterator type name matches the
method (into_iter -> IntoIter).ParseAddrError, matching ParseIntError). Drop weasel words —
Manager, Service, Factory, Helper, Util rarely belong in a type name; name the thing for what it is
(Bookings, not BookingService), append a quality only when it does something specific (BookingDispatcher).Builder is Rust's name for a factory. Accept impl Fn() -> Foo rather than a FooBuilder parameter.&str over &String, &[T] over &Vec<T>, &T over T when not
consuming. Return owned values; borrow in parameters..clone() as a signal, not a fix. A clone to satisfy the borrow checker usually means lifetimes or ownership
are structured wrong — split the borrow, narrow the scope, or restructure who owns the data.Rc/Arc only for genuine shared ownership (a graph, a cache, a value with no single owner), not to dodge
a lifetime annotation.&self/&T over cloning at the call site. Borrow at the narrowest scope so a
mutable borrow ends before the next access begins (non-lexical lifetimes allow this).Result<T, E>; absence-not-error returns Option<T>. Propagate with ?, do not
match-and-rewrap.thiserror (one enum, #[error("...")] per variant, #[from] for source
conversions). Applications use anyhow::Result and attach .context(...) at each layer.std::error::Error, Display, Debug, and are Send + Sync + 'static so they cross threads
and compose with anyhow/Box<dyn Error>..unwrap() and .expect() are permitted only on a provable invariant (with .expect("why this cannot fail")
documenting the proof), inside const contexts, or in tests. They are never error-propagation.Error. A panic means "stop the program" — never use panics to
communicate recoverable errors upstream, and never assume a panic will be caught. Genuinely fallible operations
(parsing, I/O, user input) return Result.NonEmptyVec or a parsed Email newtype
beats a runtime check on a raw Vec/String.fn f<T: Trait>) or impl Trait in argument and return position.
Monomorphization keeps it allocation-free and inlinable.dyn Trait only for genuine runtime polymorphism — heterogeneous collections (Vec<Box<dyn Draw>>), plugin
boundaries, or breaking deep monomorphization. Always write dyn explicitly (Box<dyn Error>, &dyn Handler);
bare-trait-object syntax has been an error since edition 2021.impl Trait in argument position is shorthand for an anonymous generic; in return position it hides a concrete type.
Switch to a named generic when the caller must name the type or supply it via turbofish.Debug on every public type, plus Clone, Copy, PartialEq,
Eq, Hash, PartialOrd, Ord, Default as semantics allow. Implement Display for types meant to be read by
humans (errors, string-like wrappers).From (which gives Into free), TryFrom, AsRef, AsMut — not
ad-hoc methods, so generic code and ? interoperate..iter().filter().map().collect()), not manual index loops. They
are bounds-check-friendly, lazy, and clearer.for x in &collection over for i in 0..collection.len(); index only when the index itself is the data.match arms must be exhaustive — let the compiler enforce that every variant is handled rather than ending with a
catch-all _ that silently swallows new variants.if let / while let for single-pattern matches, and let ... else { return / continue / bail } to bind-or-
bail in one line instead of nesting the happy path inside a match.let, match arms) rather than reaching into fields by .0/.field
afterward.Pick the concurrency model from the workload before writing any concurrent code — this decision is not interchangeable:
par_iter). Never reach for async here — async provides zero parallel speedup for CPU work; it only interleaves
tasks at .await points on (often) a single logical flow.Further rules once the model is chosen:
Arc<Mutex<T>> / Arc<RwLock<T>>; immutable shared data via Arc<T>. Move work and
ownership across threads with channels (std::sync::mpsc, crossbeam, or tokio::sync in async).Send (and usually Sync) so they work under Tokio and behind runtime abstractions. A !Send
value held across an .await makes the whole future !Send — keep Rc/RefCell out of async scopes that span an
await.std::thread::sleep, no synchronous file/network I/O, no long CPU loops on the runtime.
Offload CPU work with tokio::task::spawn_blocking or a rayon pool, and use the runtime's async timers/IO.references/async.md before writing async code.mod.rs-free layout: a module foo lives in foo.rs, its submodules in foo/bar.rs. Never create new
mod.rs files.[lints] (or [workspace.lints]) table in Cargo.toml, not in scattered #![deny(...)]
attributes or RUSTFLAGS. This keeps lint policy in one auditable place and inherited across the workspace.#[expect(lint, reason = "...")], not #[allow] — expect
warns when the lint stops firing, preventing stale overrides. (#[allow] is acceptable on generated code/macros.)[workspace.lints] and [workspace.dependencies]. Split a
crate when a submodule is independently useful — many small crates compile faster and prevent dependency cycles.unsafe confined to the smallest possible module; soundness boundaries are module boundaries. Every unsafe
block carries a // SAFETY: comment justifying it. Never write sound-looking safe wrappers over unsound assumptions.Code is not done until these pass (run via Bash, surfacing each command):
cargo fmt --check — formatting is non-negotiable; never hand-format.cargo clippy --all-targets --all-features -- -D warnings — Clippy clean across the whole build graph, warnings as
errors. Fix the cause; suppress a lint only with a scoped #[expect(..., reason = "...")].cargo nextest run and cargo test --doc — nextest is the fast test runner but does not execute doctests, so
the separate --doc run is mandatory to keep documentation examples honest.cargo deny check (or cargo audit) — gate dependencies for advisories, license, and source policy.//! documents the crate root and modules; /// documents items (functions, types, fields, variants). Write docs as
part of the change, not after.# Examples, # Panics (when the fn can panic), # Errors (what a Result
returns on failure), # Safety (the invariants a caller of an unsafe fn must uphold).? for fallible calls (wrap the body so it returns Result), never .unwrap() — examples are also
documentation of idiomatic usage.#![warn(missing_docs)] so every public item is documented. Link related items with intra-doc links
([Type], [mod::func]).A rust-analyzer LSP is configured for .rs files. For semantic navigation, use LSP tools — they understand types,
traits, and macro expansion in ways text search cannot:
Use Grep/Glob only for non-semantic text: comments, string literals, config files, log messages, Cargo.toml entries.
Reaching for Grep to find a definition or all callers is a mistake when the LSP resolves it precisely.
the-coder and apply these rules within it.#[test]/integration/doctest layout, cargo-nextest, proptest, insta,
criterion, mockall, rstest). When writing or reviewing tests, that skill leads; it relies on this skill for general
language conventions and on references/async.md for async-test mechanics.When writing Rust:
mod.rs, a different
error crate), follow the codebase and note the divergence once rather than fighting it file-by-file.When reviewing Rust:
unsafe, blocking-in-async, panics-as-errors, data races) over style
nits; let cargo fmt and Clippy carry the mechanical issues.The borrow checker is a collaborator, not an adversary. When it pushes back, the answer is almost never .clone(),
Rc, or unsafe — it is a clearer ownership structure. Encode invariants in types so wrong code does not compile, keep
unsafe rare and justified, and let the toolchain gates (fmt, clippy, nextest + doctests, deny) be the final word on
done.
references/anti-patterns.md (opens in a new tab)references/api-guidelines.md (opens in a new tab)references/async.md (opens in a new tab)references/documentation.md (opens in a new tab)references/edition-2024.md (opens in a new tab)references/errors.md (opens in a new tab)references/idioms.md (opens in a new tab)references/parallelism.md (opens in a new tab)references/structure.md (opens in a new tab)references/toolchain.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub xobotyi/cc-foundry --plugin rust2 skills in this plugin
Other plugins' skills for the same job