← ClaudeAtlas

stand-rustlisted

Rust coding standards. Use when writing Rust code. Covers edition, error handling with thiserror/anyhow, unsafe policy, type patterns, testing, documentation, and dependency management.
lgtm-hq/ai-skills · ★ 0 · AI & Automation · score 66
Install: claude install-skill lgtm-hq/ai-skills
# Rust Standards Standards for Rust code. ## Edition - Use the latest stable edition (2021+) - Set `edition` explicitly in `Cargo.toml` ## Toolchain - Follow the `lint` skill for formatting and linting — lintro runs `rustfmt`, `clippy`, `cargo_audit`, and `cargo_deny` as configured - Treat clippy warnings as errors in CI (`-D warnings`) - Customize formatting via `rustfmt.toml` where needed ## Error Handling - Use `thiserror` for library error types — derive structured, typed errors - Use `anyhow` for application-level error propagation - No `.unwrap()` in library code — use `?` or return `Result` - `.expect()` only with descriptive messages explaining the invariant: ```rust // Good let config = load_config().expect("config.toml must exist at startup"); // Bad let config = load_config().unwrap(); ``` - Implement `std::fmt::Display` for all custom error types - Non-panicking `.unwrap_or_default()`/`.unwrap_or()` over trivial-arm matches: ```rust // Don't let count = match maybe_count { Some(n) => n, None => 0, }; // Do let count = maybe_count.unwrap_or(0); ``` ## Type Patterns - Prefer newtypes for domain concepts — `struct UserId(u64)` over bare `u64` - Use `impl Trait` in argument position for flexibility; explicit generics in return position for clarity - Derive `Debug` on all public types - Derive `Clone`, `PartialEq`, `Eq`, `Hash` where semantically appropriate - Prefer `&str` over `String` in function arguments; ret