Rust
Purpose
Rust-specific guidelines for safe, idiomatic, maintainable code.
Core Principles
- •Leverage ownership & borrowing for safety
- •Explicit error handling > panics
- •Use standard tooling for formatting & linting
Rules
Style & Tooling
- •Format w/
rustfmt - •Run
clippy, address correctness warnings - •Use modules for clear scope & visibility
Error Handling
- •Prefer
Result&Optionoverunwrapin production - •Add context w/
thiserrororanyhowwhen appropriate
Performance
- •Avoid premature optimization; measure w/ benchmarks
- •Use iterators & slices vs manual indexing when possible
Examples
✅ "Return Result, propagate errors w/ ?"
❌ "Call unwrap() in code paths that can fail"
Edge Cases
- •Tests or prototypes:
unwrapacceptable w/ comment - •Unsafe code: doc invariants & required conditions
See COMMON.md.