agentleFS
uswuthuswuth/rustoria/skills/production/rust-production/SKILL.md

rust-production

Skill0 starsChanged 36 days agoMITView on GitHub

Use when designing, reviewing, or shipping production Rust.

The file

We split this skill into the rules it gives an agent

10 rules. About 0 are common, 4 are distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before adding any third-party dependency:

    line 21
  2. Distinctive:

    Add the dependency when it provides justified value: materially more capability, ergonomics, portability, performance, ecosystem …

    line 27
  3. Very specific:

    Never silently discard errors: propagate, handle, or log.

    line 71
  4. Very specific:

    Prefer message passing (channels) over shared memory.

    line 76
  5. Very specific:

    No blocking calls in async contexts: spawn_blocking for blocking work, async-native crates for I/O.

    line 77
  6. Very specific:

    Avoid unnecessary clones: borrow (&T, &str) instead of cloning.

    line 87
  7. Distinctive:

    Test edge cases, error paths, and concurrency (not just the happy path).

    line 94
  8. Distinctive:

    No SQL string interpolation — use parameterized queries.

    line 110
  9. Very specific:

    No shell-string construction — pass Command args as an array.

    line 111
  10. Very specific:

    No blocking in async; no casual unwrap() in production paths.

    line 132

≈ “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-production — Engineering for Production

Principles and decision guidance for production Rust. Reference-oriented; deep dives live in references/production.md, references/architecture.md, references/security.md, references/testing.md, references/performance.md.

When to use

  • Designing or reviewing Rust architecture, APIs, error handling, concurrency, or deployment.
  • Shipping or operating Rust services.
  • Reviewing code for production readiness.

Native-first dependency rule

The decision chain: NATIVE FIRST -> VERIFY NEED -> CHOOSE DEPENDENCY -> VERIFY MAINTENANCE.

Before adding any third-party dependency:

  1. Does std already provide this capability?
  2. Does std's semantics and performance suffice for the requirement?
  3. What does the crate provide beyond std?
  4. Weigh maintenance, security, MSRV, compile time, binary size, ecosystem maturity, and operational cost.
  5. Add the dependency when it provides justified value: materially more capability, ergonomics, portability, performance, ecosystem compatibility, or domain functionality that std does not reasonably provide.

This is not "never use dependencies." It is: understand native capabilities first, then introduce dependencies intentionally. A crate that wraps a std API with no added value is a liability; a crate that provides real capability (async runtime, serialization, database drivers) is justified. For the per-capability breakdown (what std covers and when a dependency wins), see the capability decision table in rust-std.

Engineering decision checklist

For any non-trivial design decision, ask:

  • Ownership: Who owns this data? Who can mutate it? When is it dropped? Is the ownership model idiomatic?
  • Error paths: Is this recoverable or fatal? What context should the error carry? ? or match? What does the caller need to know?
  • Concurrency: Is this Send? Is this Sync? Do I need Arc, Mutex, or channels? What are the failure modes (poisoning, deadlock, starvation)?
  • Async: Is this I/O-bound or CPU-bound? How is cancellation handled? What is the backpressure strategy?
  • Performance: Where are the allocations? Where are the clones? Is this cache-friendly? Have I measured, or am I guessing?
  • Dependencies: Is the crate maintained? What is the license? What is the compile-time cost? Does std already do this?
  • API design: Is this minimal? Is it difficult to misuse? Is it documented? Does it follow Rust API guidelines?
  • Testing: What are the edge cases? How do I test concurrency? How do I test async code? Are there doc-tests?

Architecture

  • Feature-oriented structure for domain code: features/users/, features/orders/ — each feature owns its models, logic, and tests. Prefer this over rigid controllers/services/repositories layering when the domain is the primary axis of change.
  • Module boundaries: expose only what the module's facade needs. Adding a feature must not require editing a shared god-module. Dependencies point inward: features depend on common, never the reverse.
  • Workspaces for multi-crate projects: [workspace.dependencies] for version inheritance, shared lints, one lockfile. See references/toolchain.md.
  • Small project ≠ toy architecture; production ≠ enterprise overengineering. No microservices, CQRS, event sourcing, or DI containers unless the problem demands them.
  • Growth test: a 5-feature project must grow to 50 features without touching unrelated modules. If adding a feature edits common/, the boundary is wrong.

Error handling

  • Libraries return concrete error types implementing std::error::Error (+ Send + Sync + 'static for anyhow interop). Use thiserror for derive-based error enums.
  • Applications may use anyhow for ergonomic error propagation; Box<dyn Error> only at the outermost boundary.
  • ? propagates; map_err adds context; ok_or/ok_or_else converts Option to Result.
  • Never silently discard errors: propagate, handle, or log. .ok() is not error handling.
  • unwrap()/expect() only in tests, demos, or provably-infallible cases — never in production paths.

Concurrency

  • Prefer message passing (channels) over shared memory; use Arc<Mutex<T>>/Arc<RwLock<T>> when shared state is necessary.
  • No blocking calls in async contexts: spawn_blocking for blocking work, async-native crates for I/O.
  • tokio::spawn requires Send + 'static — values alive across .await become part of the future.
  • Mutex poisoning: lock() returns LockResult; recover with into_inner() only when safe.
  • Atomics: default SeqCst; weaken only with a correctness argument. See references/concurrency.md.

Performance

  • Measure first (criterion, flamegraph on Linux, std::hint::black_box discipline so the optimizer cannot elide measured work). Optimize only measured hot paths.
  • Pre-allocate with Vec::with_capacity/String::with_capacity when size is known.
  • Avoid unnecessary clones: borrow (&T, &str) instead of cloning; Cow for clone-on-write.
  • Iterators are lazy — chain without intermediate collect().
  • Release profiles: lto, codegen-units = 1, strip, panic = "abort" where appropriate. See references/performance.md.

Testing

  • Unit tests for pure functions; integration tests via tests/; doc-tests for examples that must stay correct.
  • Test edge cases, error paths, and concurrency (not just the happy path).
  • cargo test runs unit + integration + doc tests; tests within a binary already run in parallel. Use cargo nextest for process-per-test isolation (a crashing test cannot take down siblings) and faster scheduling.
  • Property tests (proptest) for invariants; snapshot tests (insta) for output stability.
  • Coverage: cargo tarpaulin or llvm-cov — aim for meaningful coverage, not a number.

Observability

  • Structured logging with tracing (spans, events, propagation). Never hold a span guard across .await.
  • Metrics: metrics crate 0.21+ handle API (counter!("x").increment(1), histogram!("x").record(v)).
  • Health checks, graceful shutdown (signal handling, JoinSet, CancellationToken), correlation IDs.
  • Config: layered (defaults → file → env), secrets via secrecy::SecretString, never in code or logs.

Security

  • Validate all untrusted input at the boundary; canonicalize paths before use (fs::canonicalize + prefix check).
  • No SQL string interpolation — use parameterized queries.
  • No shell-string construction — pass Command args as an array.
  • Integer overflow: debug builds panic, release wraps — use checked_*/saturating_*/wrapping_* explicitly.
  • cargo audit + cargo deny in CI for dependency hygiene. See references/security.md.

Production readiness checklist

  • Compiles with cargo clippy -- -D warnings and cargo fmt --check
  • cargo test green (unit + integration + doc)
  • No unwrap()/expect() in production paths
  • Errors are typed, contextual, and propagated or handled
  • Concurrency primitives chosen deliberately; poisoning handled
  • No blocking in async; cancellation is safe
  • Dependencies justified (native-first rule applied)
  • Observability: logs, metrics, health checks, graceful shutdown
  • Security: input validation, no injection, secrets managed
  • MSRV declared and CI-tested; edition appropriate
  • Documentation: README, doc comments, examples

House rules

  • Native first: std before crates.
  • No blocking in async; no casual unwrap() in production paths.
  • Version-sensitive advice names its version.
  • Examples use edition 2021.

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.