/aimi-engineering:rust-conventionsfrom aimi-engineering
Guides Rust code writing and review with conventions for ownership, error handling, module organization, naming, and clippy/rustfmt CI setup.
Ships in aimi-engineering. 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.
Condensed, actionable Rust conventions for writing and reviewing Rust code —
ownership idioms, Result/Option error handling, module organization,
naming, and the clippy/rustfmt CI gate. Deep-dive material and extended
examples live under references/; this file carries everything needed to
make a Rust convention decision without reading further.
Attribution and verification: The rules below adapt guidance from the official Rust Programming Language book, the Rust API Guidelines, and Clippy's own documentation — all three dual-licensed MIT OR Apache-2.0. Every claim in this file was cross-checked against those sources' current documentation via the Context7 MCP before being finalized. See
NOTICE.mdfor full attribution and license text.
unwrap() on fallible paths, a leaking mod.rs/file-per-module mix).clippy/fmt
gate.thiserror or anyhow for its
error type.Let the compiler enforce ownership; let convention decide how to work with
it. The borrow checker will not let unsound code compile — but it will
happily accept code that clones its way past every borrow error. Idiomatic
Rust prefers &T/&mut T (borrowing) over .clone()/move by default,
reserving .clone() for when ownership genuinely must be duplicated
(crossing a thread boundary, storing owned data past the borrower's
lifetime) rather than as a reflexive fix for a compiler complaint. Every
other rule below exists to keep that discipline consistent across a crate.
&T (or &mut T when mutation is needed) in function signatures
by default; only take an owned T when the function must store, move, or
transform-and-return the value..clone() when ownership genuinely needs duplicating — not as
a default response to a borrow-checker error. Excessive .clone() calls
sprinkled through a codebase to silence the compiler are a sign the
ownership/lifetime structure needs restructuring, not a style choice.Rc/Arc/RefCell/Mutex solve a specific sharing or interior-mutability
problem (shared ownership across a graph, mutation behind an immutable
API, cross-thread shared state). Reach for them deliberately, for that
problem — not as a default escape hatch the moment the borrow checker
pushes back. Rc<RefCell<T>> in particular is worth a second look before
reaching for it reflexively: it usually means the data model or lifetime
structure could be simplified instead.impl AsRef<Path>, impl IntoIterator<Item = T>) over a concrete
collection type — so callers aren't forced into unnecessary conversions.
See references/naming-and-api-design.md for the full flexibility
guidance and examples.Result<T, E>; values that are optional but
never an error return Option<T>. Never encode "might not have a value"
or "might fail" with sentinels (-1, empty-string, magic numbers).? operator instead of manual match/unwrap
chains at every fallible call — this is Rust's idiomatic, compiler-assisted
propagation mechanism.thiserror)
so callers can match on failure variants. Application/binary crates use
a broad, ergonomic error type (commonly anyhow::Error) since their
caller is a human or a log, not code that branches on failure mode. This
"thiserror for libraries, anyhow for applications" boundary is widely-held
community consensus among Rust practitioners, corroborated by multiple
independent sources — it is not an official rust-lang policy or a rule
enforced by any tool. Treat it as a strong default, not a spec
requirement: a library that legitimately only has one caller, or an
application that re-exports part of itself as a library, can reasonably
deviate..unwrap()/.expect() are fine in tests, quick prototypes, and call
sites where the invariant is compiler-provable (e.g. indexing a
fixed-size array you just constructed) — not on paths that handle
untrusted or fallible input in production code. Clippy's unwrap_used
and expect_used lints enforce this, but they live in the allow-by-default
clippy::restriction group — they do nothing until a crate opts in
explicitly (#![warn(clippy::unwrap_used)], a [lints.clippy] table in
Cargo.toml, or equivalent). See references/error-handling.md for the
opt-in config, thiserror/anyhow examples, and the forbidden-pattern
detail.foo.rs + a foo/ sibling directory
for its submodules) over the older foo/mod.rs-in-every-directory style
for new code. The Rust Book itself now names the first "the modern,
idiomatic style" and the second "the older style" — functionally
equivalent, but mixing both conventions within the same crate is
confusing (and using both for the same module is a compiler error).pub use re-exports at the
crate root, keeping internal module structure free to be reorganized
without breaking downstream consumers. Keep internals pub(crate) (or
private) and re-export only the flat, stable surface consumers need — the
Book's own guidance for "Exporting a Convenient Public API" is exactly
this pattern.Debug,
Clone, PartialEq, Default, etc.) via #[derive(...)] rather than
hand-rolled equivalents — this is what lets a type interoperate naturally
with formatting, collections, and comparisons across the ecosystem.references/module-organization.md for a worked crate layout and the
pub use re-export pattern in full.Rust's ecosystem-wide naming convention, enforced by rustfmt/clippy::style
and near-universally followed:
| Item | Convention | Example |
|---|---|---|
| Types, traits, enum variants | UpperCamelCase | struct Config, trait Messenger, enum Status { Active } |
| Functions, methods, modules, variables | snake_case | fn read_config(), mod error_handling, let max_size |
| Constants, statics | SCREAMING_SNAKE_CASE | const MAX_SIZE: usize = 1024; |
| Type parameters | concise UpperCamelCase, usually one letter | struct Container<T> |
| Lifetimes | short lowercase, usually one letter | 'a, 'de |
| Macros | snake_case! | my_macro!() |
Acronyms count as one word in UpperCamelCase (Uuid, not UUID; Stdin,
not StdIn) and are lower-cased in snake_case (is_xid_start). See
references/naming-and-api-design.md for the full table (crates, features,
conversion-method prefixes as_/to_/into_) and derive-trait guidance.
cargo clippy and cargo fmt --check run in CI as a hard gate, not
an optional nicety. Clippy catches idiom violations (needless clones,
manual patterns with a stdlib equivalent, etc.) that rustc alone will
not flag; rustfmt removes formatting bikeshedding entirely.cargo clippy only
prints them. Set RUSTFLAGS="-Dwarnings" or run
cargo clippy --all-targets --all-features -- -D warnings so warnings
(including clippy lints) fail the build, per Clippy's own CI
documentation. See references/clippy-ci.md for GitHub Actions/GitLab
snippets and the useful lint groups beyond the default set (pedantic,
restriction, nursery)..unwrap()/.expect() on Result/Option in library or production
code paths that handle untrusted or fallible input, instead of
propagating with ? or handling Err/None explicitly.anyhow::Error (or an equally opaque boxed
error) as its public error type, forcing every downstream consumer into
a type they cannot match on.Rc<RefCell<T>> (or Arc<Mutex<T>> in single-threaded
code) to "get past" a borrow-checker complaint instead of restructuring
ownership..clone() calls used to silence the borrow checker instead of
restructuring lifetimes/borrows.foo.rs + foo/ and foo/mod.rs module-file conventions
inconsistently within the same crate.Before accepting a Rust change, confirm:
&T) rather than take ownership unless
ownership is genuinely needed; .clone() calls have a specific reason.Result<T, E>; optional-but-not-erroring
values return Option<T>; ? propagates instead of manual matches.thiserror enum for
a library, a broad anyhow::Error for an application binary — and that
boundary is understood as strong convention, not a spec rule..unwrap()/.expect() calls are confined to tests, prototypes, or
compiler-provable invariants.mod.rs), and the public API is a curated set of pub use re-exports.cargo clippy and cargo fmt --check as a gate that actually
fails on warnings (-D warnings), not just prints them.For the full-depth material behind these condensed rules — additional examples, the complete RFC 430 table, and CI configuration snippets — read on demand (not auto-loaded):
references/error-handling.md — Result/? in depth, the
thiserror/anyhow boundary with examples, unwrap_used/expect_used
lint configuration.references/module-organization.md — file-per-module vs mod.rs layout,
pub use re-export pattern, pub(crate) internals.references/naming-and-api-design.md — full RFC 430 table, conversion
method naming (as_/to_/into_), derive-trait and generics/flexibility
guidance.references/clippy-ci.md — CI snippets (GitHub Actions, GitLab CI,
Travis), clippy lint groups (pedantic, restriction, nursery) and
configuration.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
rust-conventions, ownership, error-handling, clippy, rustfmt, idiomatic-rust
19 skills in this plugin
/agent-browserBrowser automation using Vercel's agent-browser CLI. Use when you need to interact with web pages, fill forms, take screenshots, or scrape data. Alternative to Playwright MCP - uses Bash commands with ref-based element selection. Triggers on "browse website", "fill form", "click button", "take screenshot", "scrape page", "web automation"./agent-native-architectureBuild applications where agents are first-class citizens. Use this skill when designing autonomous agents, creating MCP tools, implementing self-modifying systems, or building apps where features are outcomes achieved by agents operating in a loop./npx claudepluginhub aimi-so/aimi-engineering-plugin --plugin aimi-engineeringOther plugins' skills for the same job