rust-conventions

Solid

Rust code conventions covering edition 2024, cargo fmt/clippy, Result-based error handling, unsafe discipline, async with tokio, API-guideline naming, trait implementations, benchmarking, and security scanning. Load when writing or reviewing Rust code.

Code & Development 137 stars 13 forks Updated today MIT

Install

View on GitHub

Quality Score: 86/100

Stars 20%
71
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

- 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 `&str` over `String` in params, `Cow<'_, str>` for conditional ownership, `Arc` for shared ownership. - `impl Trait` in argument position for static dispatch, `dyn Trait` for 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: `tokio` runtime, `'static + Send + Sync` bounds, `tokio::spawn` for concurrency. - Security: `cargo audit` for CVE scanning, `cargo deny` for license and advisory policies. - Dependencies: pin versions, commit `Cargo.lock`, prefer well-maintained crates. - Structured logging (spans and events, e.g., the `tracing` crate) — not `println!`. - API naming: follow `as_`/`to_`/`into_` conventions for conversions, `iter()`/`iter_mut()`/`into_iter()` for iterators. Getters are `field()` not `get_field()`. See [Rust A...

Details

Author
Goldziher
Repository
Goldziher/ai-rulez
Created
1 years ago
Last Updated
today
Language
Go
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category