agentleFS
fatihaydin9fatihaydin9/rust-development-skill/skills/rust-development/SKILL.md

rust-development

Skill1 starsChanged 5 months agoApache-2.0View on GitHub

Provides context-sensitive guidance for designing, implementing, reviewing, refactoring, debugging, testing, and organizing Rust crates and workspaces. Use this skill for Cargo manifests, ownership and borrowing, error handling, traits, async and concurrency, dependency selection, libraries, CLI tools, systems code, and backend services.

9 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

28 rules. 0 are common, 10 are distinctive, and 18 are very specific to this project.

  • 0

    Common

    Most of the 9 edited versions we read keep these.

  • 10

    Distinctive

    This author's own choices. Worth a look.

  • 18

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    When a rule points to references/, read the relevant file before performing that kind of work.

    line 20
  2. Distinctive:

    Run the narrowest relevant checks first, then formatting, linting, and tests when the environment permits.

    line 30
  3. Very specific:

    Prefer the standard library when it is sufficient.

    line 40
  4. Very specific:

    Avoid unsafe unless the task requires it.

    line 41
  5. Very specific:

    Use .clone() intentionally.

    line 48
  6. Very specific:

    Do not wrap state in Rc<RefCell<_>> or Arc<Mutex<_>> merely to silence the borrow checker.

    line 49
  7. Very specific:

    Use exhaustive matches for enums you own when every variant needs an explicit decision.

    line 55
  8. Distinctive:

    Use newtypes when two values share a representation but have different meaning, validation, or API contracts.

    line 56
  9. Very specific:

    Use #[non_exhaustive] selectively for public library APIs that intentionally reserve room for new fields or variants.

    line 58
  10. Very specific:

    Avoid unwrap() outside tests, examples, prototypes, and statically proven invariants.

    line 69
  11. Distinctive:

    Prefer consumer-owned traits: define the smallest capability next to the code that consumes it, and let adapters implement it.

    line 73
  12. Distinctive:

    Do not create traits for a single implementation unless they express a real boundary, enable testing, or support multiple behaviors.

    line 74
  13. Very specific:

    Do not block an async executor.

    line 86
  14. Very specific:

    Do not hold a synchronous mutex guard across .await.

    line 87
  15. Distinctive:

    Prefer bounded channels so overload has backpressure.

    line 88
  16. Distinctive:

    Use channels for ownership transfer and workflows.

    line 89
  17. Very specific:

    Treat cancellation as part of correctness: a future may be dropped at any .await.

    line 90
  18. Distinctive:

    Start with one crate and clear modules unless independent deployables, reusable libraries, adapter isolation, compile-time boundaries, or …

    line 95
  19. Very specific:

    Keep main.rs focused on configuration, composition, and process lifecycle.

    line 96
  20. Very specific:

    Default to private visibility, use pub(crate) for crate internals, and treat every public item as an API commitment.

    line 97
  21. Very specific:

    Follow the repository's module layout.

    line 98
  22. Very specific:

    Use conventional naming: try_new for fallible constructors.

    line 99
  23. Very specific:

    Read references/project-layout.md before scaffolding or reorganizing a project.

    line 100
  24. Very specific:

    Keep focused unit tests near the implementation and integration tests in tests/.

    line 104
  25. Distinctive:

    Prefer tests through public behavior.

    line 105
  26. Distinctive:

    Use mocking libraries only when interaction-heavy testing is genuinely clearer than a fake or in-memory implementation.

    line 107
  27. Distinctive:

    Keep a small set of adapter integration tests against real infrastructure because fakes cannot prove SQL, serialization, networking, or …

    line 108
  28. Very specific:

    Use --all-features only when all features are designed to coexist.

    line 122

“Common” is measured: kept by at least 6 in 10 of the 9 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.

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

Rust Development

Produce idiomatic, maintainable Rust while preserving the target repository's intent. Treat the rules below as context-sensitive defaults, not reasons to rewrite a working project into a preferred architecture.

When a rule points to references/, read the relevant file before performing that kind of work.

Workflow and decision precedence

Before changing code:

  1. Inspect Cargo.toml, workspace manifests, rust-toolchain.toml, repository instructions, nearby modules, and tests.
  2. Preserve the existing edition, MSRV, runtime, feature strategy, naming, error model, and architecture unless the task requires changing them.
  3. Identify the project type: library, CLI, backend service, systems component, WASM, embedded/no_std, or mixed workspace.
  4. Make the smallest coherent change that satisfies the request. Do not introduce a workspace, async runtime, abstraction layer, or dependency without a concrete need.
  5. Run the narrowest relevant checks first, then formatting, linting, and tests when the environment permits.
  6. Report commands run, failures encountered, and checks that could not be run.

Existing repository conventions outrank this skill unless they create a correctness, safety, or explicit user-requirement conflict.

Core standards

  • For new projects, prefer Rust 2024. For existing projects, keep the current edition unless migration is part of the task.
  • Respect the declared rust-version; do not raise MSRV accidentally through syntax or dependency changes.
  • Format with cargo fmt. Aim for warning-free Clippy under the repository's configured targets and features.
  • Prefer the standard library when it is sufficient. Add dependencies deliberately; read references/crates.md before recommending or adding crates.
  • Avoid unsafe unless the task requires it. Isolate necessary unsafe code behind a safe API, minimize its surface, document invariants, and place a // SAFETY: comment immediately before each unsafe block.

Ownership and API signatures

  • Accept borrowed views when the function does not need ownership: &str instead of &String, &[T] instead of &Vec<T>.
  • Choose return ownership from semantics and lifetimes. Return references or iterators for views tied to self; return owned values when the caller needs independence or the value is constructed locally.
  • Store owned data such as String when the struct must own it. Use impl Into<String> sparingly, mainly for ergonomic constructors where the generic surface is worthwhile.
  • Use .clone() intentionally. Repeated cloning of the same data is a signal to reconsider ownership, data layout, or API boundaries, but a small clear clone is often better than complex lifetime plumbing.
  • Do not wrap state in Rc<RefCell<_>> or Arc<Mutex<_>> merely to silence the borrow checker. Establish ownership and mutation boundaries first.
  • Let receivers communicate behavior: &self reads, &mut self mutates, and self consumes. Consuming methods are useful for state transitions and builders.

Type modeling

  • Represent mutually exclusive states with enums carrying variant-specific data. Prefer types that make invalid states hard or impossible to construct.
  • Use exhaustive matches for enums you own when every variant needs an explicit decision. Avoid _ catch-alls that hide newly added variants.
  • Use newtypes when two values share a representation but have different meaning, validation, or API contracts. Type aliases are appropriate for genuine shorthand, not type safety.
  • Parse at boundaries: validated types should have private fields and fallible constructors or FromStr/TryFrom implementations so inner code can rely on their invariants.
  • Use #[non_exhaustive] selectively for public library APIs that intentionally reserve room for new fields or variants. Do not add it automatically to application-internal types or truly closed sets.
  • Derive only useful traits. Do not expose secrets through derived Debug; redact them manually or use a secret wrapper.

Error handling

  • Fallible functions return Result<T, E> and propagate with ?.
  • Libraries and reusable domain/application code should expose typed errors at the abstraction level callers can act on. thiserror is useful but not mandatory.
  • Application edges such as main and CLI orchestration may use anyhow with contextual messages. Do not leak anyhow::Error into a stable library API without a deliberate reason.
  • Preserve source errors with #[source], #[from], or explicit wrapping. Do not flatten diagnostic evidence into variants such as Database(String).
  • Carry fields that handlers need for decisions, while avoiding secrets and unnecessary implementation details.
  • Map domain/application errors to transport concerns in one boundary layer with an exhaustive match when practical.
  • Avoid unwrap() outside tests, examples, prototypes, and statically proven invariants. Prefer propagation, explicit handling, or an expect message that explains the invariant. Libraries must not panic on ordinary bad input.

Traits and abstraction

  • Prefer consumer-owned traits: define the smallest capability next to the code that consumes it, and let adapters implement it.
  • Do not create traits for a single implementation unless they express a real boundary, enable testing, or support multiple behaviors. Concrete types are often simpler.
  • Choose generics when static dispatch, inlining, or type-level specialization has clear value. Choose trait objects at application boundaries when they simplify composition, reduce generic propagation, or support heterogeneous implementations.
  • Dependency injection is usually constructor arguments and explicit composition. Do not introduce a DI framework without a project-specific need.
  • For public async traits, decide whether returned futures must be Send. A Trait: Send + Sync bound alone does not guarantee that each method's future is Send. Use an explicit fn -> impl Future + Send, a deliberate boxing strategy, or the repository's established async-trait approach. See references/patterns.md.
  • For transaction abstractions, an associated transaction type and consuming commit(tx) can encode commit-once semantics. Use this pattern only when the application owns a transactional boundary.
  • Implement From for infallible conversions and TryFrom/FromStr for fallible ones. Callers receive the corresponding Into/TryInto implementations automatically.

Async and concurrency

Apply this section only to async or concurrent code.

  • For new networked backend applications, Tokio is a strong default unless the project already uses another runtime. Keep reusable libraries runtime-agnostic where practical.
  • Do not block an async executor. Use async I/O, tokio::task::spawn_blocking for unavoidable blocking work, and runtime timers rather than std::thread::sleep inside async code.
  • Do not hold a synchronous mutex guard across .await. Drop it first, redesign the critical section, or use an async mutex only when a lock truly must span an await.
  • Prefer bounded channels so overload has backpressure. Justify unbounded channels with an explicit upper-bound or failure strategy.
  • Use channels for ownership transfer and workflows; use shared locking for small, well-bounded shared state. Consider an actor when one task can naturally own the state and lock coordination is spreading.
  • Treat cancellation as part of correctness: a future may be dropped at any .await. Put must-run cleanup in guards and multi-step consistency in transactions or idempotent protocols.
  • Rust prevents data races, not deadlocks, starvation, ordering bugs, or lost work. Design and test those properties explicitly.

Project structure

  • Start with one crate and clear modules unless independent deployables, reusable libraries, adapter isolation, compile-time boundaries, or ownership boundaries justify a workspace.
  • Keep main.rs focused on configuration, composition, and process lifecycle. Put testable behavior in library modules.
  • Default to private visibility, use pub(crate) for crate internals, and treat every public item as an API commitment.
  • Follow the repository's module layout. For new modules, foo.rs with a foo/ subdirectory is a clear modern layout; do not reorganize existing mod.rs trees without a reason.
  • Use conventional naming: try_new for fallible constructors; as_ for cheap borrowed views, to_ for allocating conversions, and into_ for consuming conversions; capability-oriented trait names rather than IThing.
  • Read references/project-layout.md before scaffolding or reorganizing a project. Backend workspace layouts in that file are options, not universal requirements.

Testing

  • Keep focused unit tests near the implementation and integration tests in tests/. Async tests should use the project's runtime test macro.
  • Prefer tests through public behavior. Assert structured error variants and relevant fields rather than display strings.
  • Hand-rolled fakes work well for narrow consumer-owned traits, but a fake transaction must stage changes and apply them only on successful commit. Do not model rollback with type Tx = () when transaction behavior matters.
  • Use mocking libraries only when interaction-heavy testing is genuinely clearer than a fake or in-memory implementation.
  • Keep a small set of adapter integration tests against real infrastructure because fakes cannot prove SQL, serialization, networking, or migration behavior.
  • Compile documentation examples with cargo test --doc when the crate exposes them.

Quality gates

Adapt commands to the repository's workspace and feature model. A typical baseline is:

cargo fmt --all --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
cargo audit

Use --all-features only when all features are designed to coexist; otherwise test a feature matrix. Add cargo deny check, release builds, MSRV checks, and cargo semver-checks when the project warrants them. Commit Cargo.lock for applications and binaries; follow the repository's policy for libraries.

Avoid these patterns

  • Type aliases presented as semantic type safety.
  • Error variants that stringify and discard source errors.
  • Provider-owned god traits imported into business logic.
  • Database, web framework, or async runtime dependencies in a supposedly runtime-agnostic domain/model crate.
  • Shared locking as the automatic answer to ownership problems.
  • Blocking calls inside async tasks or synchronous guards held across .await.
  • Business rules embedded in transport handlers or main.rs.
  • Panics on normal user or network input.
  • Unbounded queues without capacity reasoning.
  • Public async traits whose Send behavior is left accidental.
  • "Outbox" implementations that write an event row but rely only on an immediate in-process publish without a durable relay.
  • unsafe without stated invariants and a safe boundary.

Reference files

  • references/patterns.md — consumer-owned async traits with explicit Send futures, transactional state plus outbox writes, a rollback-aware fake, composition root, actor pattern, typed configuration, and graceful shutdown. Read for services, repositories, async boundaries, or long-running applications.
  • references/project-layout.md — single-crate and workspace layouts, Cargo configuration, naming conventions, and CI. Read before scaffolding or reorganizing a project.
  • references/crates.md — dependency-selection guidance and current candidates by category. Read before adding dependencies or recommending a crate.

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.