Eric Rust
- Use structs and enums for explicit data shapes, and newtypes for IDs.
- Keep Rust modules small: keep tightly coupled code together, split distinct concepts into sibling files, and use a directory with
mod.rswhen one feature owns multiple submodules. - Use
thiserrorfor reusable/API errors andanyhowat application edges. Match typed error variants instead of checking error strings. - Use
gardefor input and DTO validation: derive attributes for field rules, custom validators for cross-field or collection invariants. - Use
schemarsfor JSON Schema andts-rsfor TypeScript DTO export, unless the project has an established contract export flow.