# Rust Project Guidance ## Project Layout - Prefer a workspace for multi-crate projects. - Binary crate: `src/main.rs` thin; logic in `src/lib.rs` or modules. - Library crate: `src/lib.rs` public API; internal modules private. - Tests: `tests/` integration; unit tests co-located. ## Error Handling - Libraries: define `enum Error` with `thiserror`. - Applications: use `anyhow::Result` at boundaries. - Avoid `unwrap()`/`expect()` in production. ## Design Patterns - Newtype, Builder, trait objects, From/Into, Default, enum state machines, RAII/Drop, interior mutability. ## Async - Use tokio; avoid blocking in async; use spawn_blocking; channels for message passing. ## Testing - Unit + integration; property tests with proptest. ## Tooling - cargo fmt, clippy, test, doc, audit, deny. ## Common Crates - CLI: clap, dialoguer, indicatif, console, tracing. - Web: axum, actix-web, reqwest, tower, tower-http. - DB: sqlx, diesel, sea-orm. - Errors: thiserror, anyhow, miette. - Testing: proptest, mockall, wiremock, assert_cmd.