Rust Code Quality and Standards
Relevant Rust source files
Cargo.tomlrustfmt.toml.pre-commit-config.yamldeny.tomldocs/developer_guide/rust.md
Formatting, lints, types, tests, and review work together. None substitutes for the others. cargo fmt defines surface consistency; Clippy detects many correctness and maintainability hazards; the compiler enforces ownership and type contracts; tests and runtime probes validate behavior.
API design
Prefer domain-specific types over primitives, checked constructors at external boundaries, explicit error values for recoverable failures, and builders only when they materially simplify configuration. Public types should document invariants, units, timestamp meaning, feature availability, and failure behavior.
Provider and persistence types stop at adapters. Core engines should consume nautilus-model values and narrow ports. Avoid introducing a second canonical market model or leaking SDK structs through service interfaces.
Error handling
Use structured errors with enough context to identify the operation and relevant identifier without exposing credentials. Panics are appropriate only for violated internal invariants or intentionally infallible test construction. Network, parsing, configuration, database, and user-input failures must remain recoverable results.
Unsafe and concurrency
Constrain unsafe code to small modules with stated invariants and tests around the safe boundary. Document thread ownership and shutdown behavior for channels, shared state, and background tasks. Do not hold locks across asynchronous waits or external calls.
Documentation and examples
Examples should compile against the public Rust API and show feature requirements. Keep comments focused on non-obvious reasons. A copied binding example is not Rust documentation; translate the workflow into the native crate or state explicitly that no Rust API exists at the pinned revision.
Run formatting and Clippy with the workspace-selected toolchain. Review the actual diff after automatic fixes, especially around feature-gated code and generated artifacts.