rust-best-practices
Skill1 starsChanged 52 days agoMITView on GitHub
Use whenever you write, change, or review Rust code: ownership, API design, errors, crates, docs, and tests.
57 other projects use a version of this, 4 of them edited.
Adopted by
Most recently taken up by
- nooblk-98/burnbartheir own version, first seen Nov 29, 2026
- existential-birds/beagletheir own version, first seen Nov 29, 2026
- Furyfree/ai-workflowtheir own version, first seen Nov 29, 2026
- sshine/managed-skillstheir own version, first seen Nov 29, 2026
- TudorAndrei/skillstheir own version, first seen Nov 29, 2026
- sajaddp/sonjoo-seo-audittheir own version, first seen Nov 29, 2026
Used with
Projects with it also use rust-port, rust-async-patterns and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
fedemeloSkillrust-port
Port code from C, C++, Python, Go, JavaScript, or TypeScript into idiomatic Rust that keeps the original behavior: ownership instead of manual memory, Result instead of error codes and exceptions, enums instead of flag ints and magic strings, and tests that prove the port matches. Use this whenever the user asks to port, translate, convert, migrate, or rewrite code in Rust ("rewrite this in Rust", "what would this look like in Rust", "move this module to Rust"), even if they don't say "port". Pairs with the rust-best-practices skill, which covers the target code's style.
Also in 5 projects that use this
klauswgSkillrust-async-patterns
Master Rust async programming with Tokio, async traits, error handling, and concurrent patterns. Use when building async Rust applications, implementing concurrent systems, or debugging async code.
Also in 11 projects that use this
GitHubSkillrust-mcp-server-generator
Generate a complete Rust Model Context Protocol server project with tools, prompts, resources, and tests using the official rmcp SDK
Also in 3 projects that use this
CloudflareSkillrust-review
Rust code review for workerd. Covers CXX FFI safety, unsafe code patterns, JSG resource conventions, error handling, and a review checklist adapted from the C++ review skills. Load this skill when reviewing Rust code in src/rust/.
Also in 6 projects that use this
huialiSkillrust-testing
Also in 9 projects that use this
gihwan-devSkilltauri-v2
Tauri v2 cross-platform app development with Rust backend. Use when configuring tauri.conf.json, implementing Rust commands (#[tauri::command]), setting up IPC patterns (invoke, emit, channels), configuring permissions/capabilities, troubleshooting build issues, or deploying desktop/mobile apps. Triggers on Tauri, src-tauri, invoke, emit, capabilities.json.
Also in 7 projects that use this
Other versions57 projects use a version of this.
Word for word · 0
None found.
Edited · 4
- morganlinton/BeautifulRust★ 1.8k78% same
- Cosmian/kms★ 38023% same
- tuan3w/herdr-mobile★ 4076% same
- fedemelo/agent-config★ 478% same
Wrote their own version · 53
- farm-fe/farm★ 5.6ksame name
- crbnos/carbon★ 2.9ksame name
- pedronauck/skills★ 659same name
- openbezal/rhema★ 354same name
- apollographql/apollo-mcp-server★ 323same name
- apollographql/skills★ 138same name
- microsoft/scope★ 93same name
- existential-birds/beagle★ 91same name
- Blushyes/reef★ 84same name
- baekenough/oh-my-customcode★ 47same name
43 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository13 other files it gives its agents.
- rules/AGENTS.mdAGENTS.md
- file-prSkill
- full-sendSkill
- full-stopSkill
- golang-developmentSkill
- human-writerSkill
- implementSkill
- implement-specSkill
- no-commentsSkill
- python-developmentSkill
- review-changesSkill
- spec-reviewSkill
- typescript-developmentSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
18 rules. 0 are common, 4 are distinctive, and 14 are very specific to this project.
0
Common
Most of the 56 edited versions we read keep these.
4
Distinctive
This author's own choices. Worth a look.
14
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 22
Run these and fix everything they report:
- Very specific: line 31
Check every feature combination the project supports.
- Very specific: line 33
When cargo fmt reformats files you did not change, revert those files.
- Very specific: line 49
Use indices into an owning Vec, or Rc<RefCell<_>> with Weak back-pointers, as a last resort.
- Very specific: line 87
If you implement len(), implement is_empty().
- Very specific: line 97
Independent flags: use the bitflags crate; an enum models exactly one choice.
- Very specific: line 105
Put trait bounds on the impl blocks that need them, not on struct definitions: #[derive(Clone)] struct Good<T>, not struct Bad<T: Clone + …
- Very specific: line 138
Prefer, in order: concrete types.
- Very specific: line 140
Keep required trait methods minimal and provide defaults for everything derivable from them, as Iterator does from next.
- Very specific: line 141
If a function has a clear receiver, make it a method.
- Distinctive: line 143
Keep parameter order consistent across a crate: call-specific first, ubiquitous context (loggers, allocators) last.
- Distinctive: line 151
When the module has no tests, pin the current behavior with a few before you touch it.
- Very specific: line 179
If a fallible function consumes an argument, return it inside the error so the caller can retry without cloning (FromUtf8Error::into_bytes).
- Very specific: line 180
Keep anyhow::Error out of a library's public API.
- Very specific: line 213
Dependencies: every one costs compile time, binary size, and supply-chain exposure, including build.rs and proc macros.
- Very specific: line 216
Run code only from main() onward (no ctor-style crates).
- Very specific: line 222
Document what the signature can't say: preconditions, side effects, ownership transfer, and complexity.
- Distinctive: line 235
Read the one that matches the task.
“Common” is measured: kept by at least 6 in 10 of the 56 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Rust best practices
Distilled from five Rust style and design guides, with a digest of each in references/. Where they disagree, this file says which to follow.
The repository's conventions, edition, toolchain, and MSRV win over this file. A design record (an ADR or an architecture note) wins when it states its reason. One without a reason is an open question: report it rather than follow it. Code, rustdoc, and tests describe current behaviour, so a design record that disagrees with them is stale. A change that reverses a design record updates that record in the same change.
To review Rust code, also read references/review.md.
1. Mindset
- Write Rust-shaped code. Model errors with
Result, resources with ownership andDrop, polymorphism with traits and enums, and nullability withOption. Inheritance-flavored tricks (Derefto a "base" struct,Manager/Factorytypes,throw_if_nullhelpers) are smells. - Make invalid states unrepresentable. Push invariants into types: enums instead of bool flags and "must be X if Y" rules, newtypes for units and IDs, fallible constructors that validate once. Then the compiler enforces the rule.
- Application code is not library code. Library code (anything with external users) follows the API-design rules below strictly. Application code favors simplicity and directness: concrete types,
Stringor&strrather thanimpl Into<String>parameters,anyhow-style errors,Vecreturn values, no speculative generality.
2. Before you hand back code
Run these and fix everything they report:
cargo fmt
cargo clippy --all-targets -- -D warnings
cargo test
cargo doc --no-deps # libraries: catches broken doc links and missing docs- Check every feature combination the project supports.
--all-featuresworks only when features are additive; a project with mutually exclusive features names its combinations in CI. - A project that runs
cargo nextest runalso needscargo test --doc, because nextest skips doctests. - When
cargo fmtreformats files you did not change, revert those files. - Fix a lint rather than silencing it. When a lint is genuinely wrong for one item, use
#[expect(clippy::name, reason = "...")]on the narrowest item.expectwarns when the lint stops firing, so stale suppressions get cleaned up. Use#[allow]only in generated code or macro output. - Enforce warnings-as-errors in CI with
cargo clippy -- -D warnings, never with#![deny(warnings)]in source: new toolchains add warnings and break the build. - Configure lints once in
Cargo.toml([lints]or[workspace.lints]), not with scattered crate attributes.
3. Ownership and borrowing
Prefer unique ownership. Reach for Rc/Arc only when shared ownership is part of the design, and for RefCell/Mutex only when interior mutability is. They move checking from compile time to run time, so use them on purpose.
Clone only data you mean to copy. A clone that exists only to end a borrow produces a silent copy whose later changes are lost. Try these first, in roughly this order:
- Extend a temporary with a named
let, or shorten a borrow with a block. - Split a long expression into typed intermediates so the failing step is visible.
- Move a field out of
&mut selfwithstd::mem::take(needsDefault),std::mem::replace, orOption::takeinstead of cloning it. - Split a large struct into smaller ones so disjoint fields can be borrowed separately. The compiler tracks disjoint field borrows inside one function, but not across method calls.
- Clone small, immutable data deliberately.
- Use indices into an owning
Vec, orRc<RefCell<_>>withWeakback-pointers, as a last resort. Avoid self-referential structs.
fn a_to_b(e: &mut MyEnum) {
if let MyEnum::A { name, x: 0 } = e {
*e = MyEnum::B { name: std::mem::take(name) };
}
}Accept the most general borrowed type. &str not &String, &[T] not &Vec<T>, &T not &Box<T>, Option<&T> not &Option<T>. Deref coercion then lets callers pass owned values, borrows, or literals. Where you only read a path, string, or byte buffer, impl AsRef<Path> / impl AsRef<str> / impl AsRef<[u8]> is fine on parameters (never on struct fields; store PathBuf and String). Library code that only iterates takes impl IntoIterator<Item = T>; application code may take &[T].
Take ownership only when you need it, and then take it by value. If a function stores or consumes its argument, take T, not &T plus an internal .clone(). If it only reads, take &T; if it mutates in place, &mut T. Return multiple values as a tuple or struct, not through &mut out-parameters (reusing a caller-owned buffer, as Read::read does, is the exception).
Prefer owned data in structs. A struct holding &'a T forces a lifetime onto every container. Owning a String or Vec<u8> is usually simpler and rarely the bottleneck. When a type does carry a lifetime, give it a descriptive name ('src, 'conn); '_ and 'a are fine on simple functions.
Freeze after setup. Build with let mut, then rebind let data = data; so later code cannot mutate it by accident.
Keep Rc, Arc, Box, and RefCell out of public signatures. Take &T, &mut T, or T and let callers decide how to own things. A service that must be shared implements a cheap Clone by wrapping its state in Arc<Inner> internally.
4. Types and API design
Naming
| Item | Case | Notes |
| Types, traits, enum variants | UpperCamelCase | Acronyms are one word: Uuid, HttpClient |
| Functions, methods, modules, locals | snake_case | |
| Constants, statics | SCREAMING_SNAKE_CASE | |
| Type parameters | short, from the main bound | T, R: Read, W: Write |
| Lifetimes | short lowercase | descriptive when on a type |
- No
get_prefix on getters:fn len(&self),fn name(&self) -> &str,fn name_mut(&mut self). Use baregetonly when there is one obvious thing to get (Cell::get). Related:set_foo(T),take_foo(),with_foo(|f| ..)for closure access, and unsafe_uncheckedsiblings for checked accessors. - Conversion prefixes signal cost and ownership:
as_(free, borrow to borrow),to_(expensive, borrow to owned or borrow to borrow),into_(consumesself). Putmutin type order:as_mut_slice, notas_slice_mut. - Constructors:
new(primary),with_capacity/new_with_foo(variants),try_new(fallible),from_foo(conversion; pair important ones with aFromimpl). I/O resources use domain verbs:File::open,TcpStream::connect. An unvalidated constructor gets a name that says so, nevernew. iter/iter_mut/into_iterreturn types namedIter/IterMut/IntoIter;keys()returnsKeys.- Error types read verb-object-error:
ParseBoolError, notBoolParseError. - Name the thing a type is (
Bookings,Dispatcher,FooBuilder) instead of a weasel suffix such asService,Manager,Factory,Helper, orUtil. Leave the module name out of the type (foo::Id, notfoo::FooId). Avoid abbreviations an outsider wouldn't know. - If you implement
len(), implementis_empty(). - Feature names are bare:
std,serde,alloc, neveruse-stdorno-std.
Model the domain with types
- Newtypes for semantic distinctions:
struct Miles(f64)andstruct Kilometers(f64)cannot be mixed, where a type alias can. Add#[repr(transparent)]when layout matters, and derive or forward the traits you need. A newtype that encodes an invariant (Month) validates in a fallible constructor (TryFrom,FromStr,try_new) and never offers an infallibleFromfrom the raw type. - Enums or named methods instead of
boolparameters in public or shared signatures.report(true)is unreadable at the call site and cannot grow a third mode. Use a two-variant enum (Verbosity::Summary,Verbosity::Full) or two methods (report(),report_verbose()):Widget::new(Size::Small, Shape::Round), notWidget::new(true, false). A private helper whose call sites sit a few lines away may keep itsbool. - Named fields over tuples, except single-field newtypes and very local code.
Optionfor absence, never sentinels such as-1or"". Data-carrying enums instead of "field X is only meaningful when Y is set".- Use the strongest std type:
PathBuf/&Pathfor paths,Durationfor spans,NonZeroU32internally only (keep plain integers at API boundaries). - Independent flags use the
bitflagscrate; an enum models exactly one choice.
Derive and implement the standard traits eagerly
Downstream crates cannot add std traits to your types (orphan rule), so you must. Derive whenever every field supports it: Debug (on every public type; hand-write it to redact secrets), Clone (except unique resources and key material), Copy (only small bitwise-copyable types, because the compiler copies silently), PartialEq / Eq, PartialOrd / Ord (never ship PartialOrd without Ord when a total order exists), Hash (consistent with Eq), and Default when an obvious neutral value exists. Implement Display for anything meant to be read: error types, string-like wrappers. Add #[must_use] to pure functions and to types, such as errors and lazy values, whose discarding is a bug.
Implement From / TryFrom, never Into / TryInto directly (blanket impls give you those). Prefer from / into over as, which silently allows lossy casts. Implement FromStr rather than an ad-hoc from_str method, FromIterator and Extend on collections, and IntoIterator for both owned and borrowed forms. Implement Deref only on smart pointers and owning collections (Vec<T> to [T]), never to fake inheritance. Overload operators only for their mathematical meaning.
Put trait bounds on the impl blocks that need them, not on struct definitions: #[derive(Clone)] struct Good<T>, not struct Bad<T: Clone + Debug>.
If you hand-write Ord, hand-write PartialEq, PartialOrd, and Hash to agree with it (compare the same fields, ignore the same fields). A derived PartialEq next to a custom Ord breaks the std contract and misbehaves in BTreeMap and sort/dedup. Say in the docs which fields equality ignores.
Constructors, builders, defaults
- Provide
new()even whenDefaultexists, and make them agree (one delegates to the other). Derive or implementDefaultso callers can write..Default::default(); bag-of-options structs with public fields always have it. - When the caller must make a choice that has no safe default, such as a trust or security policy, take an enum with data-carrying variants and no
Default, and give the unsafe variant a name that says so. ADefaultthere picks the policy for every caller who never read the docs. - Up to two optional parameters: inherent constructors (
new,with_a,with_b). Beyond that, or when construction validates or has side effects, add a builder:Foo::builder()returnsFooBuilder, setters are named after fields (timeout(d), notset_timeout) and infallible, andbuild() -> Result<Foo, Error>does all validation including cross-field checks. Prefer non-consuming setters (&mut self -> &mut Self) unlessbuildmust move a value out. - A constructor with four or more loose arguments groups them into semantic types:
Deposit::new(account, amount)rather than four&str/u64parameters.
Visibility and evolution
- Private by default. Fields stay private unless the struct is passive C-style data. Widen to
pub(crate)orpub(super)beforepub. Making an item more public later is non-breaking; the reverse is breaking, and everypubitem is a promise. Public fields,Copy, auto traits,const fn, and every#[doc(hidden)] pubitem are such promises too. - Mark a new public enum or public-field struct that crosses crate boundaries
#[non_exhaustive]when you introduce it, unless the set is a stable ontology. Adding the attribute to an existing public type, or to an options struct callers build with..Default::default(), is a breaking change. - In a
matchon your own enums, list every variant. Keep a_arm only for a foreign#[non_exhaustive]enum, after the variants you handle. Seal traits you don't want implemented downstream, and say so in the docs:
pub trait TheTrait: private::Sealed { /* ... */ } mod private { pub trait Sealed {} impl Sealed for usize {} }- Library code returns iterators, not a
Veccollected only to return, behindimpl Iterator<Item = T>(internal APIs) or a newtype (public APIs you must keep stable). - Expose each public item at exactly one path.
pub usea foreign crate's items only in an umbrella crate. Keep third-party types out of your public API; feature-gateserdeimpls behind a feature namedserde. If a dependency's type must appear, re-export it so callers can name the matching version. - Mark a function
constonly if it will stayconst. KeepErrorKindenums and other internals private when they would lock in failure modes you consider private.
Traits and generics
- Define a trait only for generic programming (
T: Trait,impl Trait,dyn Trait) or as an extension trait (FooExt), never only to organize code. Put essential functionality in inherent methods and have trait impls forward to them, so callers need no import. - Prefer, in order: concrete types; generics (
T: Trait,impl Trait);dyn Trait, ideally wrapped in your own struct (struct DynStore(Arc<dyn Store>)). Generics give static dispatch and inlining; trait objects give heterogeneous collections and smaller binaries. Keep generics on service-level types one level deep (Service<Backend>, notService<Backend<Store>>). - Decide early whether a trait must be object-safe. Generic methods or
Selfoutside the receiver break it; exclude such methods withwhere Self: Sized. - Keep required trait methods minimal and provide defaults for everything derivable from them, as
Iteratordoes fromnext. - If a function has a clear receiver, make it a method. A computation with no receiver is a free function, not
Database::check(params). Associated functions are for construction. - Closures: use the most general bound that works (
FnOnceif called once,FnMutif it mutates, elseFn) and preferFn*bounds to barefnpointers. Closure parameters go last, one per function. - Keep parameter order consistent across a crate: call-specific first, ubiquitous context (loggers, allocators) last.
- Reach for a macro only when functions, generics, and traits cannot do the job. Prefer
macro_rules!to proc macros, make macro input look like the output it generates, and keep a type's kind and a function's signature as written.
Refactoring someone else's code
- Fix every smell the request is about, not just the cheap ones: clones that only satisfy the borrow checker,
&String/&Vec<T>parameters,unwrapon fallible paths,Rc<RefCell<_>>in signatures,get_getters,boolparameters,+string concatenation,#![deny(warnings)], error types withoutError, nondeterministicHashMapiteration in output. - Keep public behavior identical unless changing it is the point: the same operations, the same success and failure semantics, the same output bytes. Turning a panic into an
Erris the change callers want. Dropping an error variant, removing a derive, or changing what a constructor takes is not; if a signature must change, show the before and after in the change list and say why. - Preserve quirks you don't understand and flag them, rather than silently "fixing" them.
- When the module has no tests, pin the current behavior with a few before you touch it.
5. Errors and panics
Pick the mechanism by contract:
| Situation | Use |
Absence is normal (first(), checked_add) | Option<T> |
| The caller may need to know what went wrong | Result<T, E> |
| A bug or violated invariant inside your code | panic! / assert! / expect("why") |
Panics are not exceptions. A panic means "stop now". Report bad input with Result. A library lets panics propagate: catch_unwind does nothing under panic = "abort" and can leave state inconsistent. Where a panicking convenience is justified, pair it with a fallible API (v[i] / v.get(i), new / try_new) and document it under # Panics.
Every intentional panic carries a message with the relevant values: assert!(buf.len() >= HEADER, "buffer too small: {} bytes", buf.len()), expect("config should be loaded before workers start"). Prefer expect("reason") to unwrap(). Phrase the expect message as the expectation that failed, not a restatement of the condition.
Pattern-match instead of check-then-unwrap: if let Some(v) = opt { .. } or let Some(v) = opt else { return .. };, never if opt.is_some() { opt.unwrap() }.
Lock poisoning is fatal: .lock().expect("lock poisoned"). Don't recover with into_inner.
A function that verifies or checks returns Err when the check fails, so check(..)? stops the caller. A bool result lets the caller forget to look.
Library error types (any E in a public Result):
- Implement
std::error::Error(which requiresDebug+Display), beSend + Sync + 'static, and implementsource()for wrapped causes. A library's public error type is never(),String, orBox<dyn Error>. Displaymessages are lowercase, concise, and have no trailing punctuation:"invalid header length".- Implement
From<Upstream>so?converts. Usemap_erronly for foreign errors or to add context. - Two sound shapes: an enum with one variant per cause (
thiserrorgenerates this well), or a struct with a privatekindplusis_xxx()and accessor methods, asstd::io::Errordoes. Prefer an error per operation when callers handle each operation's failures differently. Expose only details callers can act on. - If a fallible function consumes an argument, return it inside the error so the caller can retry without cloning (
FromUtf8Error::into_bytes). - Keep
anyhow::Errorout of a library's public API.
Application error handling: anyhow or eyre with .context("opening config") is the right tool. Use one app-level error type, not several. main may return Result<(), anyhow::Error>.
Destructors never fail, panic, or block. Provide close(self) -> Result<()> for fallible teardown and let Drop do best-effort cleanup.
Document failure modes: # Errors for any Result, # Panics for any reachable panic, # Safety for every unsafe fn.
6. Everyday idioms
- Iterators over hand loops when the pipeline is short and reads top-down:
values.iter().filter(..).map(..).collect(),.any(),.sum(),.fold(). Collect fallible steps intoResult<Vec<_>, E>and apply?. Keep an explicitforloop when the body is large, does several jobs, or needs awkward early returns. Bind a long chain to a named variable rather than putting it in aforheader, and preferfor x in itto.for_each(|x| ..). Option/Resultcombinators (map,and_then,ok_or_else,unwrap_or_else,as_ref,as_deref) when they're clearer thanmatch, andmatchwhen they're not.format!/write!with inline args (format!("{name}: {count}")) for concatenation and substitution, not chained+orstr::replace.write!into an existing buffer in hot paths.- Explicit types where inference obscures intent: on
.into(),.parse(),.collect(), and complex iterator results. Preferlet x: Vec<u32> = ..to a turbofish. - Drop guards for cleanup that must run on early return or unwind. Bind them to a name (
let _guard = ..), becauselet _ = ..drops immediately. Closures that capture mixed ownership: rebind in a block, then
move:let job = { let cfg = cfg.clone(); move || run(cfg, data) };- Import style: one
useper module path (use foo::bar::{Bar, Baz};); types and traits imported and used unqualified (Regex); free functions qualified by their module (mem::take,fs::read). Import a trait inside the function that needs it unless the whole file uses it. Globs only foruse super::*in tests,use Enum::*in a function that matches on it, and a framework's documented prelude. - Magic numbers become named
consts. - Logging: structured events through
tracingorlog, notprintln!/dbg!, except for a CLI's own stdout output.
7. Crates, modules, dependencies
- Prefer small, single-purpose crates split along real component boundaries, in a flat
crates/workspace; keep each crate out of another crate'ssrc/. Split when a crate grows a second purpose. Share versions and lints through[workspace.dependencies]and[workspace.lints]. - Modules: name a leaf module after its primary item (
Foolives infoo.rs). Non-leaf modules contain onlymoddeclarations and re-exports. Put the essential items at the crate root and group the rest by use case (account,network), not by kind (traits,errors). Don't define a prelude. - Re-export individually (
pub use foo::{A, B};), never with a glob. - Dependencies: every one costs compile time, binary size, and supply-chain exposure, including
build.rsand proc macros. Enable only the dependency features the project needs. Use ranges ("1","1.4"), never"*"or a needless"=". CommitCargo.lockfor binaries. Audit withcargo tree --duplicates,cargo deny,cargo udeps, andcargo audit. - Features are additive and bare-named:
std,serde,alloc,test-util. A feature adds public items; it never removes or changes one, and it never gates a struct field or a trait method. Put mocks and fakes behindtest-util. - Semver: breaking changes include removing or renaming public items, adding a variant to an enum that isn't
#[non_exhaustive], adding a field to a publicly constructible struct, adding a trait bound, or making a trait non-object-safe. Deprecate in a minor release before removing in a major one. Use the latest stable edition for new crates and set an MSRV deliberately. The Cargo SemVer reference lists every case. - Run code only from
main()onward (noctor-style crates). Use unstable features only on a nightly toolchain.
8. Documentation
///on every public item;//!at the top of every public module and the crate root. The first sentence is a single line of about fifteen words, because it becomes the summary in listings.- Sections, in this order, as applicable:
# Examples,# Errors,# Panics,# Safety. Examples use?with thefn mainhidden behind#lines, neverunwrap(), because users copy them verbatim. Describe parameters in prose, not a table. - Document what the signature can't say: preconditions, side effects, ownership transfer, and complexity.
/// Removes an element.onremove_elementrestates the name and adds nothing. - Link items with
[`Type`]. Hide impls users never trigger (From<PrivateError> for PublicError) with#[doc(hidden)].
9. Tests
- Unit tests in
#[cfg(test)] mod tests { use super::*; .. }for private internals. Integration tests intests/for anything reachable through the public API, and prefer that location when either would do. Doc examples are tests too. - Cover each feature combination and each platform-specific path.
- Anything doing I/O, time, randomness, or network must be mockable:
new_mocked() -> (Self, MockCtrl)behindtest-util, not aDefaultthat performs I/O. - Fuzz parsers of untrusted input with
cargo fuzz. Benchmark withcriterionordivanandstd::hint::black_box. Run Miri overunsafe. - Assertions get context so failures read well:
assert_eq!(got, want, "input {input:?}").
References
Read the one that matches the task. The first three cover code most crates do not have; the rest are digests of one source each, for the reasoning behind a rule or a complete checklist.
references/review.md: reviewing Rust code; what to look for, in priority order.references/concurrency-and-async.md: threads, locks, channels,async, orSendbounds.references/unsafe-and-ffi.md:unsafe, FFI, or-syscrates.references/performance.md: optimizing after a measurement.references/rust-api-guidelines.md(https://rust-lang.github.io/api-guidelines/): designing a public API or crate; all 54 checklist items with conventions.references/effective-rust.md(https://www.lurklurk.org/effective-rust/): choosing between alternatives: generics vsdyn,Resultvs panic, iterators vs loops, borrow-checker tactics, dependencies, CI.references/rust-design-patterns.md(https://rust-unofficial.github.io/patterns/): idioms, patterns, and anti-patterns with code.references/microsoft-rust-guidelines.md(https://microsoft.github.io/rust-guidelines/): error struct design, panic policy, unsafe policy, async, workspace layout, performance.references/google-rust-style-guide.md(https://google.github.io/styleguide/rustguide.html): formatting, imports, module layout, accessor naming, application vs library.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

