scombat/rust icon
public
Published on 6/11/2025
Rust Rules

A sleek, modern illustration of the Rust programming language: a gear-shaped logo surrounded by snippets of Rust code with syntax highlighting, a terminal window showing cargo build, and an organized file tree (src/, Cargo.toml). Background with a dark theme and orange/bronze highlights. Style: minimalist, dev-centric, clean.

Rules

Project Structure - Organize code with lib.rs, main.rs, and clear module hierarchy. - Use src/bin/ for multiple binaries; avoid cramming everything into main.rs.

Code Quality - Enforce use of clippy and rustfmt before committing. - Favor Result<T, E> over panics in libraries. - Document public functions, structs, and modules with /// doc comments.

Dependency Management - Keep Cargo.toml clean; avoid unused or overly permissive dependencies. - Use specific versions (no *) and prefer crates with good maintenance.

Error Handling - Prefer typed errors (custom Error enums) over anyhow in libraries. - Use thiserror or eyre for ergonomic error management when appropriate. - Avoid using .unwrap() or .expect() outside of tests or prototyping.

Testing & CI - Write unit tests alongside code; use #[cfg(test)] blocks. - Favor assert_eq!, assert_matches!, and structured error testing. - Include basic CI tasks: cargo check, cargo test, cargo clippy.

Unsafe & Performance - Avoid unsafe unless there's no alternative and document its usage explicitly. - Profile performance before optimizing; use cargo bench, perf, or criterion.

AI Response Formatting - If asked for Rust code, return a complete, compile-ready example by default. - Avoid unnecessary explanation unless explicitly requested. - Clearly mark testable vs. illustrative code snippets.