agentleFS
JakkuSakuraJakkuSakura/skills/rust-coding-style/SKILL.md

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

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    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.

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
  1. Distinctive:

    Never use a fallback branch unless explicitly instructed.

    line 19
  2. Very specific:

    Never ignore a match branch unless explicitly instructed.

    line 20
  3. Very specific:

    When placing placeholders or stubs, use todo!().

    line 23
  4. Distinctive:

    Do not use the word "plumbing".

    line 26
  5. Distinctive:

    Prefer newtypes over type aliases for invariants.

    line 37
  6. Very specific:

    Use impl Trait in return position for iterator APIs.

    line 38
  7. Distinctive:

    Never implement From/TryFrom for wrapper newtypes.

    line 44
  8. Very specific:

    Default to feature-based grouping in Rust (e.g., src/foo/mod.rs).

    line 48
  9. Distinctive:

    Only use layer-based grouping for legacy or mandated layouts.

    line 49
  10. Very specific:

    Use mod.rs to curate public APIs rather than re-exporting entire trees, unless the mods are private.

    line 50
  11. Distinctive:

    Use singular for a thing/type, plural for a collection/module.

    line 53
  12. Very specific:

    Prefer struct + impl when there is shared state, configuration, or invariants.

    line 57
  13. Distinctive:

    Prefer struct if a function has only the struct as parameter, and tie closely to the struct's purpose.

    line 58
  14. Distinctive:

    Prefer free functions for stateless operations.

    line 59
  15. Distinctive:

    Avoid OOP-style class hierarchies.

    line 60
  16. Distinctive:

    Use a builder when construction has multiple stages or invariant checks.

    line 61
  17. Distinctive:

    Prefer owning types in public APIs.

    line 64
  18. Distinctive:

    Avoid exposing explicit lifetimes unless they simplify the API.

    line 65
  19. Distinctive:

    Keep async at the edges; core logic stays sync when possible.

    line 68
  20. Very specific:

    Prefer explicit async fn in public APIs.

    line 69
  21. Very specific:

    Use tokio only when async IO or concurrency pays for the complexity.

    line 70
  22. Very specific:

    Prefer cargo criterion over cargo bench.

    line 73
  23. Very specific:

    Use cargo flamegraph for CPU hotspots.

    line 74
  24. Very specific:

    Use perf + flamegraph for low-level profiling on Linux.

    line 75
  25. Very specific:

    Use samply for sampling + flamegraphs on macOS/Linux.

    line 76
  26. Very specific:

    Use tokio-console for async task/latency insight.

    line 77
  27. Very specific:

    Use cargo llvm-lines for codegen size hotspots.

    line 78
  28. Very specific:

    Use cargo bloat for binary size breakdown.

    line 79
  29. Distinctive:

    Use Podman Compose for containerized integration tests.

    line 88

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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 match branch unless explicitly instructed. For unhandled events, use tracing with at least warn! 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 Trait in 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; avoid Option<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: use mod/ with mod.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.rs to 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.rs for a single client type, clients/ for a collection.

API style: free functions vs structs

  • Prefer struct + impl when 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 fn in public APIs; avoid boxed futures unless needed.
  • Use tokio only when async IO or concurrency pays for the complexity.

Performance

  • Prefer cargo criterion over cargo bench.
  • Use cargo flamegraph for CPU hotspots.
  • Use perf + flamegraph for low-level profiling on Linux.
  • Use samply for sampling + flamegraphs on macOS/Linux.
  • Use tokio-console for async task/latency insight.
  • Use cargo llvm-lines for codegen size hotspots.
  • Use cargo bloat for 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.