rust
Idiomatic Rust engineering: ownership/borrowing/lifetimes, traits, Result/Option, Tokio/Axum/Serde, Cargo workspaces, testing/benches. Use for Rust work; never transliterate Java/Python architectures.
SKILL.mdskills/languages/rust/SKILL.md
GitHubrust
Ownership is the design tool: encode invariants in types so illegal states do not compile.
Activate when
- Writing, reviewing, or testing Rust; choosing async runtime, web framework, serialization; Cargo workspace decisions.
Do NOT activate for
- Syntax-only questions (rustc +
cargo docanswer those faster).
Procedure
- Version: detect edition/toolchain from Cargo.toml/Cargo.lock/rust-toolchain.toml; research in https://doc.rust-lang.org/ (Book, std, Cargo) for that toolchain. Never assume latest-stable features on pinned toolchains.
- Ownership design: borrow by default; lifetimes describe real relationships, not appeasement (
'staticsprawl is a smell);Cloneonly where duplication is semantically right (Arcfor shared ownership, channels for handoff). - Errors:
Result/Optionwith?;thiserrorfor libraries,anyhowfor applications (confirm versions first); nounwrap/expectoutside tests and proven invariants. - Traits/generics: small trait bounds, behavior-first; generics with static dispatch preferred; dynamic dispatch (
dyn) only at real heterogeneity points. - Async: Tokio runtime chosen deliberately;
Send/Syncunderstood, not fought; no blocking calls inside async (usespawn_blocking); backpressure on channels. - Web/serde: Axum handlers as thin extractors + typed errors (see https://docs.rs/axum/ for the pinned version); Serde derives with explicit renames/deny-unknown-fields at trust boundaries (see https://serde.rs/).
- Cargo: workspaces with shared lockfile; features additive;
cargo test,clippy -D warnings,cargo fmt --check; benches with criterion or std harness for perf claims. - Unsafe/FFI:
unsafeminimal, documented invariants, Miri-tested where feasible; FFI boundaries validated on both sides. - Verify:
cargo test+ clippy + fmt green; perf claims backed by bench numbers; unsafe blocks listed in the PR.
Failure modes
- Fighting the borrow checker instead of remodeling ownership; hidden blocking in async;
unwrapin library code; feature unification surprises across workspace members.
References
- Registry:
../../research/documentation-search/references/framework-registry.yaml(rust, tokio, axum, serde).