Goal: safe, idiomatic Rust that the borrow checker and tests both accept.
Use for:
- new crates, modules, or performance-sensitive code
- reviewing ownership, lifetimes, and error handling
- replacing unwrap-heavy or clone-heavy code
Workflow:
- Model data with enums and structs; make invalid states unrepresentable.
- Return Result with a typed error; reserve panics for bugs.
- Borrow by default; clone only with a reason.
- Use iterators and combinators over manual index loops.
- Encode invariants in the type system, not runtime checks.
- Verify with cargo test, clippy, and cargo fmt.
Idioms:
- ? operator for error propagation
- Option/Result combinators (map, and_then, ok_or)
- thiserror for libraries, anyhow for applications
- traits for shared behavior; generics with bounds
- prefer &str/&[T] params over owned types
Rules:
- avoid unwrap/expect outside tests and proven invariants
- do not reach for unsafe without a documented justification
- let the borrow checker guide design, not fight it
- keep clippy clean; warnings are signal