rust-idioms
Skill1 starsChanged 41 days agoMITView on GitHub
Idiomatic Rust — naming conventions, the constructs that read as native Rust, clippy/rustfmt as enforcers, and a catalog of common anti-patterns. Use when writing or polishing Rust to be idiomatic, naming things, deciding "is this the Rust way?", or reviewing for code smells. Triggers: clippy, rustfmt, is this idiomatic, the Rust way, stringly typed, missing_docs.
4 other projects use a version of this.
Adopted by
Most recently taken up by
- irahardianto/awesome-agvtheir own version, first seen Oct 14, 2026
- JSBtechnologies/rustkbtheir own version, first seen Oct 11, 2026
- tstapler/dotfilestheir own version, first seen Oct 10, 2026
- jcanizalez/vibegridtheir own version, first seen Oct 9, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- irahardianto/awesome-agv★ 157same name
- jcanizalez/vibegrid★ 25same name
- tstapler/dotfiles★ 8same name
- JSBtechnologies/rustkb★ 0same name
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 repository42 other files it gives its agents.
- AGENTS.mdAGENTS.md
- addressing-findingsSkill
- auditSkill
- codebase-onboardingSkill
- codex-reviewSkill
- compatibilitySkill
- debuggingSkill
- developSkill
- distributed-racesSkill
- memorySkill
- nix-dev-envSkill
- nix-flakesSkill
- nixosSkill
- nix-packagingSkill
- nix-reviewSkill
- refactoringSkill
- retroSkill
- review-initSkill
- review-rulesSkill
- rust-architecture-reviewSkill
- rust-architectureSkill
- rust-cliSkill
- rust-cloud-nativeSkill
- rust-concurrencySkill
- rust-ecosystemSkill
- rust-embeddedSkill
- rust-errorsSkill
- rust-fintechSkill
- rust-macrosSkill
- rust-mlSkill
- rust-navigationSkill
- rust-ownershipSkill
- rust-performanceSkill
- rust-pluginsSkill
- rust-reviewSkill
- rust-securitySkill
- rust-testingSkill
- rust-traitsSkill
- rust-unsafeSkill
- rust-webSkill
- specsSkill
- sql-reviewSkill
The file
We split this skill into the rules it gives an agent
5 rules. 0 are common, 2 are distinctive, and 3 are very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 23
Follow the Rust API Guidelines — these are what clippy and other Rustaceans expect:
- Very specific: line 40
Booleans: read as predicates: is_empty, has_root, should_retry.
- Distinctive: line 61
Don't argue style by hand — let the tools.
- Very specific: line 111
Use the standard sections where they apply: # Examples, # Errors (for Result),
- Very specific: line 115
Document the *why/contract*, not the obvious *what*: /// Returns the cached value on fn cached_value() is noise.
“Common” is measured: kept by at least 6 in 10 of the 4 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 Idioms
What makes Rust read like Rust: naming the standard library would recognize, constructs the ecosystem expects, and the anti-patterns that mark code as ported-from-another-language. The idiomatic-construct catalog is in patterns.md; the smell catalog (Good/Bad) is in anti-patterns.md.
When to Use
- Writing new Rust you want to read as native
- Naming types, functions, methods, conversions
- Polishing / reviewing for idiom and code smells
- Settling "is this the Rust way?"
Naming conventions
Follow the Rust API Guidelines — these are what clippy and other Rustaceans expect:
| Item | Convention | Example |
| Types, traits, enum variants | UpperCamelCase | HashMap, IntoIterator, Pending |
| Functions, methods, vars, modules | snake_case | read_to_string, max_len |
| Constants & statics | SCREAMING_SNAKE_CASE | MAX_SIZE |
| Conversions | as_ borrow→borrow (cheap), to_ →owned (costly), into_ consume (owning) | as_str, to_owned, into_bytes |
- Getters have no
get_prefix —name(), notget_name()(get/get_mutare for indexing-style access likeslice.get(i)). - Iterators:
iter(&T),iter_mut(&mut T),into_iter(T); the iterator types they return mirror the method names —Iter,IterMut,IntoIter. - Constructors:
newfor the obvious one;with_capacity/from_*for variants. - Don't stutter:
author::Author, notauthor::AuthorStruct; a method onErrorisn'terror_kind(), it'skind(). - Booleans read as predicates:
is_empty,has_root,should_retry. - Consistent word order: pick one order for a family of names and keep it — siblings of
RecvErrorareSendError, notErrorOnSend. Don't mix verb-noun and noun-verb in one crate.
Idiomatic constructs (the short list)
Full examples in patterns.md:
- Implement
From/TryFrom; you getInto/TryIntofor free. Don't writeto_x/from_xmethods where aFromimpl belongs. Default+ struct-update (..Default::default()) over many-arg constructors.- Iterator chains (
.iter().map().filter().collect()) over index loops;collect::<Result<_, _>>()to short-circuit fallible iteration. matches!,if let, andlet … elseover verbosematchfor one-armed checks.- Accept
&str/impl AsRef<str>, return owned (→rust-ownership). derivethe common set in a conventional order:Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default(thenSerialize, Deserialize).- Minimal visibility: default private,
pub(crate)for crate-internal,pubonly at the API.
Clippy & rustfmt are the enforcers
Don't argue style by hand — let the tools. Turn them up and keep them green:
# Cargo.toml — lint this crate
[lints.clippy]
all = "warn"
pedantic = "warn"cargo fmt # formatting is not a matter of opinion
cargo clippy --all-targets -- -D warningsclippy's categories: correctness (bugs), suspicious, complexity, perf, style,
pedantic (opt-in). When you must #[allow(clippy::lint)], add a comment saying why — an
unexplained allow is itself a smell.
Documentation
Doc comments are part of the code's quality, not an afterthought — and they compile.
//! Crate- or module-level docs: what this is for, a quickstart. (top of lib.rs / a module)
/// One-line summary of what the item does (this line shows in the item list).
///
/// More detail in following paragraphs. Link other items with intra-doc links:
/// see [`Config`] and [`parse`].
///
/// # Examples
/// ```
/// # use mycrate::parse;
/// let cfg = parse("port = 8080").unwrap(); // examples are compiled & run as tests
/// assert_eq!(cfg.port, 8080);
/// ```
///
/// # Errors
/// Returns [`ParseError`] when the input isn't valid TOML.
///
/// # Panics
/// State any panic path here — or that it never panics.
pub fn parse(input: &str) -> Result<Config, ParseError> { /* ... */ }Conventions:
///documents the item that follows;//!documents the enclosing crate/module (use it for a crate-level overview at the top oflib.rs).- First line is a concise summary — it's what appears in the generated item list; lead with the verb ("Parses…", "Returns…").
- Use the standard sections where they apply:
# Examples,# Errors(forResult),# Panics,# Safety(forunsafe fn— required; →rust-unsafe). - Examples are doc tests — they're compiled and run, so they can't go stale (→
rust-testing). - Link with intra-doc links (
[`Type`]) rather than bare names — they resolve and stay valid. - Document the why/contract, not the obvious what:
/// Returns the cached valueonfn cached_value()is noise; document the invariant, the units, the edge cases. - For published crates, enforce coverage with
#![warn(missing_docs)]and treat docs as part of the semver contract →rust-ecosystem(libraries).
Boundaries
- This skill is the catalog (how to write it well). The review process — gate, severity,
verdict — is
rust-review, which cites this skill for the "why" and the fix. - Topic mechanics live in their skills: ownership fixes →
rust-ownership, error design →rust-errors, dispatch →rust-traits, sharing →rust-concurrency. This skill links to them rather than re-explaining.
Further reading
- Rust Design Patterns (rust-unofficial) — the broader community catalog of idioms, design patterns, and anti-patterns. craft owns the action-first, review-relevant subset; the book covers the rest, including the GoF patterns craft deliberately doesn't duplicate (mapped by mechanism in the GoF/SOLID Rosetta in patterns.md).
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.

