rust-coding-style
Skill1 starsChanged 9 months agoMITView on GitHub
Rust coding style and decision defaults for API design, errors, structure, naming, ownership, async boundaries, performance tools, and testing choices. Use when writing or reviewing Rust code and when choosing between design options.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- hashintel/hashtheir own version, first seen Oct 8, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- hashintel/hash★ 1.7ksame 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 repository13 other files it gives its agents.
- axum-single-page-uiSkill
- feishuSkill
- frontend-designSkill
- git-opsSkill
- gui-automationSkill
- macos-gui-automationSkill
- mermaidSkill
- npmSkill
- playrightSkill
- playwright-cliSkill
- pythonSkill
- python-uvSkill
- youtrackSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
29 rules. About 0 are common, 14 are distinctive, and 15 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈14
Distinctive · estimate
This author's own choices. Worth a look.
15
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 19
Never use a fallback branch unless explicitly instructed.
- Very specific: line 20
Never ignore a match branch unless explicitly instructed.
- Very specific: line 23
When placing placeholders or stubs, use todo!().
- Distinctive: line 26
Do not use the word "plumbing".
- Distinctive: line 37
Prefer newtypes over type aliases for invariants.
- Very specific: line 38
Use impl Trait in return position for iterator APIs.
- Distinctive: line 44
Never implement From/TryFrom for wrapper newtypes.
- Very specific: line 48
Default to feature-based grouping in Rust (e.g., src/foo/mod.rs).
- Distinctive: line 49
Only use layer-based grouping for legacy or mandated layouts.
- Very specific: line 50
Use mod.rs to curate public APIs rather than re-exporting entire trees, unless the mods are private.
- Distinctive: line 53
Use singular for a thing/type, plural for a collection/module.
- Very specific: line 57
Prefer struct + impl when there is shared state, configuration, or invariants.
- Distinctive: line 58
Prefer struct if a function has only the struct as parameter, and tie closely to the struct's purpose.
- Distinctive: line 59
Prefer free functions for stateless operations.
- Distinctive: line 60
Avoid OOP-style class hierarchies.
- Distinctive: line 61
Use a builder when construction has multiple stages or invariant checks.
- Distinctive: line 64
Prefer owning types in public APIs.
- Distinctive: line 65
Avoid exposing explicit lifetimes unless they simplify the API.
- Distinctive: line 68
Keep async at the edges; core logic stays sync when possible.
- Very specific: line 69
Prefer explicit async fn in public APIs.
- Very specific: line 70
Use tokio only when async IO or concurrency pays for the complexity.
- Very specific: line 73
Prefer cargo criterion over cargo bench.
- Very specific: line 74
Use cargo flamegraph for CPU hotspots.
- Very specific: line 75
Use perf + flamegraph for low-level profiling on Linux.
- Very specific: line 76
Use samply for sampling + flamegraphs on macOS/Linux.
- Very specific: line 77
Use tokio-console for async task/latency insight.
- Very specific: line 78
Use cargo llvm-lines for codegen size hotspots.
- Very specific: line 79
Use cargo bloat for binary size breakdown.
- Distinctive: line 88
Use Podman Compose for containerized integration tests.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Rust Coding Style
Apply these rules when writing or reviewing Rust code. Keep decisions consistent and terse.
Examples
- "Pick an error strategy for this new Rust binary."
- "Decide API shape and module layout for this Rust crate."
Guidelines
Control flow and logging
- Never use a fallback branch unless explicitly instructed.
- Never ignore a
matchbranch unless explicitly instructed. For unhandled events, usetracingwith at leastwarn!and include a{:?}debug of the event.
Placeholders and stubs
- When placing placeholders or stubs, use
todo!(). Do not create empty files.
Language
- Do not use the word "plumbing".
Error handling
- New app: prefer
thiserror. - IO-only code: prefer
std::io::Result. - Existing
eyre/anyhow: stick with it. - New library: prefer
thiserror. - Within a codebase, keep the existing error crate unless you have a strong reason to change.
API design
- Public API: return
Result<T, E>and avoid panics. - Prefer newtypes over type aliases for invariants.
- Use
impl Traitin return position for iterator APIs. - For many optional params: use a builder.
- Config load API: prefer free function
fn load(path: impl AsRef<Path>) -> Result<Config, Error>. - Iterator exposure: prefer
fn iter(&self) -> impl Iterator<Item = &Item>. - Optional config fields: use
#[serde(default)]and concrete fields; avoidOption<T>in the struct. - Validation on construction: prefer builder with
build() -> Result<Self, Error>. - Never implement From/TryFrom for wrapper newtypes. Unless they are Error types.
Code structure
- Small module: use
mod.rs; large module: usemod/withmod.rs. - Default to feature-based grouping in Rust (e.g.,
src/foo/mod.rs). - Only use layer-based grouping for legacy or mandated layouts.
- Use
mod.rsto curate public APIs rather than re-exporting entire trees, unless the mods are private.
Naming
- Use singular for a thing/type, plural for a collection/module.
- File naming:
client.rsfor a single client type,clients/for a collection.
API style: free functions vs structs
- Prefer
struct+implwhen there is shared state, configuration, or invariants. - Prefer struct if a function has only the struct as parameter, and tie closely to the struct's purpose.
- Prefer free functions for stateless operations.
- Avoid OOP-style class hierarchies; use traits for behavior and composition.
- Use a builder when construction has multiple stages or invariant checks.
Ownership and lifetimes
- Prefer owning types in public APIs; borrow internally where possible.
- Avoid exposing explicit lifetimes unless they simplify the API.
Async boundaries
- Keep async at the edges; core logic stays sync when possible.
- Prefer explicit
async fnin public APIs; avoid boxed futures unless needed. - Use
tokioonly when async IO or concurrency pays for the complexity.
Performance
- Prefer
cargo criterionovercargo bench. - Use
cargo flamegraphfor CPU hotspots. - Use
perf+ flamegraph for low-level profiling on Linux. - Use
samplyfor sampling + flamegraphs on macOS/Linux. - Use
tokio-consolefor async task/latency insight. - Use
cargo llvm-linesfor codegen size hotspots. - Use
cargo bloatfor binary size breakdown.
Testing
- In-file unit tests for local behavior and edge cases.
tests/for integration tests across modules/crates.- Shell integration tests for CLI workflows.
- Smoke tests for minimal end-to-end coverage.
- Mock tests when dependencies are expensive or flaky.
- Fuzz tests for parsers, serializers, and input handling.
- Use Podman Compose for containerized integration tests.
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.

