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.
4 other projects use a version of this.
Adopted by
Most recently taken up by
- navikt/copilottheir own version, first seen Sep 14, 2026
- feamcor/skillstheir own version, first seen Jun 4, 2026
- cosmonic-labs/skillstheir own version, first seen Feb 12, 2026
- carloss765/agent-skillstheir own version, first seen Jan 15, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- navikt/copilot★ 54same name
- cosmonic-labs/skills★ 21same name
- carloss765/agent-skills★ 1same name
- feamcor/skills★ 1same 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.
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 4 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
- Very specific: line 20
When a rule points to references/, read the relevant file before performing that kind of work.
- Distinctive: line 30
Run the narrowest relevant checks first, then formatting, linting, and tests when the environment permits.
- Very specific: line 40
Prefer the standard library when it is sufficient.
- Very specific: line 41
Avoid unsafe unless the task requires it.
- Very specific: line 48
Use .clone() intentionally.
- Very specific: line 49
Do not wrap state in Rc<RefCell<_>> or Arc<Mutex<_>> merely to silence the borrow checker.
- Very specific: line 55
Use exhaustive matches for enums you own when every variant needs an explicit decision.
- Distinctive: line 56
Use newtypes when two values share a representation but have different meaning, validation, or API contracts.
- Very specific: line 58
Use #[non_exhaustive] selectively for public library APIs that intentionally reserve room for new fields or variants.
- Very specific: line 69
Avoid unwrap() outside tests, examples, prototypes, and statically proven invariants.
- Distinctive: line 73
Prefer consumer-owned traits: define the smallest capability next to the code that consumes it, and let adapters implement it.
- Distinctive: line 74
Do not create traits for a single implementation unless they express a real boundary, enable testing, or support multiple behaviors.
- Very specific: line 86
Do not block an async executor.
- Very specific: line 87
Do not hold a synchronous mutex guard across .await.
- Distinctive: line 88
Prefer bounded channels so overload has backpressure.
- Distinctive: line 89
Use channels for ownership transfer and workflows.
- Very specific: line 90
Treat cancellation as part of correctness: a future may be dropped at any .await.
- Distinctive: line 95
Start with one crate and clear modules unless independent deployables, reusable libraries, adapter isolation, compile-time boundaries, or …
- Very specific: line 96
Keep main.rs focused on configuration, composition, and process lifecycle.
- Very specific: line 97
Default to private visibility, use pub(crate) for crate internals, and treat every public item as an API commitment.
- Very specific: line 98
Follow the repository's module layout.
- Very specific: line 99
Use conventional naming: try_new for fallible constructors.
- Very specific: line 100
Read references/project-layout.md before scaffolding or reorganizing a project.
- Very specific: line 104
Keep focused unit tests near the implementation and integration tests in tests/.
- Distinctive: line 105
Prefer tests through public behavior.
- Distinctive: line 107
Use mocking libraries only when interaction-heavy testing is genuinely clearer than a fake or in-memory implementation.
- Distinctive: line 108
Keep a small set of adapter integration tests against real infrastructure because fakes cannot prove SQL, serialization, networking, or …
- Very specific: line 122
Use --all-features only when all features are designed to coexist.
“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 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:
- Inspect
Cargo.toml, workspace manifests,rust-toolchain.toml, repository instructions, nearby modules, and tests. - Preserve the existing edition, MSRV, runtime, feature strategy, naming, error model, and architecture unless the task requires changing them.
- Identify the project type: library, CLI, backend service, systems component, WASM, embedded/
no_std, or mixed workspace. - Make the smallest coherent change that satisfies the request. Do not introduce a workspace, async runtime, abstraction layer, or dependency without a concrete need.
- Run the narrowest relevant checks first, then formatting, linting, and tests when the environment permits.
- 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.mdbefore recommending or adding crates. - Avoid
unsafeunless 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:
&strinstead 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
Stringwhen the struct must own it. Useimpl 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<_>>orArc<Mutex<_>>merely to silence the borrow checker. Establish ownership and mutation boundaries first. - Let receivers communicate behavior:
&selfreads,&mut selfmutates, andselfconsumes. 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/TryFromimplementations 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.
thiserroris useful but not mandatory. - Application edges such as
mainand CLI orchestration may useanyhowwith contextual messages. Do not leakanyhow::Errorinto 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 asDatabase(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 anexpectmessage 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. ATrait: Send + Syncbound alone does not guarantee that each method's future isSend. Use an explicitfn -> impl Future + Send, a deliberate boxing strategy, or the repository's established async-trait approach. Seereferences/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
Fromfor infallible conversions andTryFrom/FromStrfor fallible ones. Callers receive the correspondingInto/TryIntoimplementations 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_blockingfor unavoidable blocking work, and runtime timers rather thanstd::thread::sleepinside 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.rsfocused 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.rswith afoo/subdirectory is a clear modern layout; do not reorganize existingmod.rstrees without a reason. - Use conventional naming:
try_newfor fallible constructors;as_for cheap borrowed views,to_for allocating conversions, andinto_for consuming conversions; capability-oriented trait names rather thanIThing. - Read
references/project-layout.mdbefore 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 --docwhen 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 auditUse --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
Sendbehavior is left accidental. - "Outbox" implementations that write an event row but rely only on an immediate in-process publish without a durable relay.
unsafewithout stated invariants and a safe boundary.
Reference files
references/patterns.md— consumer-owned async traits with explicitSendfutures, 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.
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.

