Rust Engineering Guidelines
When modifying the locus-core crate, prioritize mechanical sympathy, safety, and strict alignment with the project's data-oriented architecture.
1. Core Principles
- Data-Oriented Architecture: Respect the cache-locality rules defined in Architecture. Design data structures as flat arrays rather than nested pointers.
- Allocation Policy: Adhere strictly to the zero-allocation hot-loop rule. Utilize
bumpalofor all ephemeral frame data (see Constraints). - Geometric Math: Use
nalgebra::SMatrixfor small, stack-allocated matrices and vectors. Avoid dynamicDMatrixunless absolutely necessary outside the hot path. - Zero Panics: Ensure no code path can panic. Rely on
Resulttypes and#![deny(clippy::unwrap_used)].
2. SIMD & Optimization
- Runtime Dispatch: Use the
multiversioncrate to compile targeted kernels for AVX2, AVX-512, and NEON architectures. - Branchless Logic: Inside pixel-processing loops, prefer branchless operations (masks, CMOVs) over unpredictable conditional jumps.
3. Documentation & Modularity
- Module Boundaries: Keep modules focused (e.g.,
threshold,quad,decoder). Hide internal implementation details behindpub(crate). - Docstrings: All public interfaces must be documented. We compile with
#![warn(missing_docs)]. Provide code examples in docstrings where applicable.
4. Verification Workflow
- Linting:
cargo clippy --workspace --all-targets --all-features -- -D warnings - Formatting:
cargo fmt --all - Always use
--release: Build and test exclusively in--releasemode for all verification and algorithmic changes. Debug performance is not representative of SIMD paths and can lead to false regressions. - Run
cargo clippyfrequently and resolve all warnings before committing.