# Rust and C++ guidance

## Preserve temporal semantics

Moving computation or allocation across an effect changes behavior when it can fail. A batch planner followed by one commit is not equivalent to an incremental loop if the original exposes partial progress.

```text
for item in items:
    apply_required_preprocessing_effect(item)
    outcome = pure_decision(item, explicit_config)
    apply_outcome(item, outcome)
    publish_audit(outcome)
```

## Rust

- Accept shared borrows in pure calculations and return a small owned outcome.
- Keep an existing mutable public boundary when callers observe in-place updates.
- Prefer enums and structs for meaningful outcomes.
- Keep a `for` loop for interleaved mutation, `?`, auditing, locking, or early exit.
- Preserve overflow behavior, panic timing, partial progress, and synchronization semantics.
- Avoid cloning merely to satisfy the borrow checker.
- Run `cargo fmt --check`, `cargo clippy -- -D warnings`, and relevant tests.

## C++

- Take pure inputs by `const&` and return a small value-oriented outcome.
- Preserve an existing non-const reference boundary when callers observe mutation.
- Prefer RAII and standard value types.
- Keep loops for ordered effects, early exits, resource lifetimes, and exception-sensitive progress.
- Treat allocation as potentially throwing.
- Preserve floating-point operation order and exception guarantees.
- Avoid `std::function` unless runtime type erasure is required.
- Compile with strict warnings and run behavioral or sanitizer tests when available.
