<< All versions
Skill v1.0.1
currentAutomated scan100/100goldziher/ai-rulez/rust-conventions
+1 new
──Details
PublishedNovember 7, 2026 at 06:23 AM
Content Hashsha256:e20ea3c9dcd6428a...
Git SHA57bee3f37d8f
Bump Typepatch
──Files
Files (1 file, 2.9 KB)
SKILL.md2.9 KBactive
SKILL.md · 28 lines · 2.9 KB
name: rust-conventions description: "Rust conventions: edition, fmt and clippy, error crates and propagation, unsafe documentation, API naming guidelines, traits, testing, benchmarks, tokio, cargo audit. Use when writing or reviewing Rust code." metadata: version: "1.0.1"
- Rust 2024 edition,
cargo fmt+clippy -D warnings, zero warnings policy. Result<T, E>with a derive-based error crate (e.g., thiserror) for library errors, a context-adding error crate (e.g., anyhow) for applications.?for propagation — never.unwrap()in library code.- Minimize
unsafe— every block needs// SAFETY:comment explaining invariants. - Prefer
&stroverStringin params,Cow<'_, str>for conditional ownership,Arcfor shared ownership. impl Traitin argument position for static dispatch,dyn Traitfor dynamic dispatch when heterogeneous collections needed.- Small, focused modules. Use
pub(crate)for internal visibility. Workspace inheritance for multi-crate repos. #[cfg(test)]for unit tests,tests/for integration, a coverage tool (e.g., cargo-llvm-cov) for coverage.- Benchmarking: a statistical benchmark harness (e.g., criterion) for microbenchmarks, profile with a flamegraph tool (e.g., cargo flamegraph).
- Async:
tokioruntime,'static + Send + Syncbounds,tokio::spawnfor concurrency. - Security:
cargo auditfor CVE scanning,cargo denyfor license and advisory policies. - Dependencies: pin versions, commit
Cargo.lock, prefer well-maintained crates. - Structured logging (spans and events, e.g., the
tracingcrate) — notprintln!. - API naming: follow
as_/to_/into_conventions for conversions,iter()/iter_mut()/into_iter()for iterators. Getters arefield()notget_field(). See Rust API Guidelines. - Eagerly implement common traits:
Clone,Debug,Default,Eq,PartialEq,Hash,Send,Sync. UseFrom/AsRef/AsMutfor conversions,FromIterator/Extendfor collections. - Type safety: newtypes for static distinctions, builder pattern for complex construction,
bitflagsover enums for flag sets. Avoidboolparams — use custom types or enums. - Constructors:
new()as static inherent methods. No out-parameters. Only smart pointers implementDeref/DerefMut. - API flexibility: minimize parameter assumptions via generics, make traits object-safe when trait objects may be useful. Let callers decide where to copy and place data.
- Rustdoc: all public items have doc examples using
?(notunwrap). Document errors, panics, and safety invariants. Hyperlink related items. - Future-proofing: seal traits to prevent downstream implementations, keep struct fields private, don't duplicate derived trait bounds on structs. See Rust Design Patterns.
- Anti-patterns:
unwrap(), unguardedunsafe, panics in libraries,Vec/HashMapacross FFI.