# Rust Coding Standards — Working draft

These are **proposed shared rules**, not automatically accepted policy for every Zevarix repository. A project may explicitly adopt the **latest `main`** guidance without maintaining a commit pin, or choose a fixed revision for a specific assurance need. It retains its own scope, exceptions and stronger local rules. Code that predates adoption is not automatically noncompliant.

For a practical review of unnecessary abstraction and repeated expensive work in generated code, see [Anti AI Slop Rust](<https://rcs.zevarix.com/ai-rust-code-quality/index.md>). The same quality expectations apply to human contributors.

## Rule levels

- **Required:** the default expectation *within an adopting project's declared scope*. Deviations need a locally documented technical reason, not permission from this repository.
- **Advisory:** a preferred design or review question. Departures may be sensible and are not automatic review failures.

For either level, reviewers report demonstrated problems with a concrete call path, trigger and impact. A rule name by itself is not proof of a defect. Tool errors block only the affected validation claim or operation; they do not end unrelated safe progress.

Rule IDs use the prefix `RCS` for **Rust Coding Standards**. The rest of each ID identifies the subject and individual rule.

## Index

| Rule | Level | Enforced by | Concern |
| --- | --- | --- | --- |
| [RCS-FMT-001](<https://rcs.zevarix.com/rules/style-and-structure/index.md#rcs-fmt-001--format-with-rustfmt>) | Required | `rustfmt` | Consistent Rust formatting |
| [RCS-NAME-001](<https://rcs.zevarix.com/rules/style-and-structure/index.md#rcs-name-001--use-idiomatic-names>) | Required | Compiler/Clippy + review | Naming conventions |
| [RCS-MOD-001](<https://rcs.zevarix.com/rules/style-and-structure/index.md#rcs-mod-001--organize-by-responsibility>) | Advisory | Human review | Cohesive modules, not line quotas |
| [RCS-META-001](<https://rcs.zevarix.com/rules/style-and-structure/index.md#rcs-meta-001--derive-package-release-versions-from-their-authority>) | Advisory | Review/tests | Use package release metadata, not duplicate version literals |
| [RCS-TYPE-001](<https://rcs.zevarix.com/rules/types-and-errors/index.md#rcs-type-001--model-consequential-identities-distinctly>) | Required\* | Review/tests | Prevent identity/unit mixups |
| [RCS-NUM-001](<https://rcs.zevarix.com/rules/numbers-and-bounds/index.md#rcs-num-001--check-consequential-arithmetic>) | Required\* | Review/tests | Checked sizes, offsets and budgets |
| [RCS-NUM-002](<https://rcs.zevarix.com/rules/numbers-and-bounds/index.md#rcs-num-002--reject-lossy-conversions-where-identity-or-size-matters>) | Required\* | Review/tests | Explicit fallible narrowing |
| [RCS-INPUT-001](<https://rcs.zevarix.com/rules/untrusted-input/index.md#rcs-input-001--bound-actual-work-not-just-declared-sizes>) | Required\* | Review/tests | Bound actual untrusted decode work |
| [RCS-INPUT-002](<https://rcs.zevarix.com/rules/untrusted-input/index.md#rcs-input-002--make-malformed-or-partial-input-outcomes-explicit>) | Required\* | Review/tests | Reject incomplete authoritative parsing |
| [RCS-API-001](<https://rcs.zevarix.com/rules/types-and-errors/index.md#rcs-api-001--follow-predictable-api-conventions>) | Advisory | Review/Clippy | Conventional Rust APIs |
| [RCS-ERR-001](<https://rcs.zevarix.com/rules/types-and-errors/index.md#rcs-err-001--use-explicit-recoverable-errors>) | Required | Review/Clippy/tests | `Result` and error propagation |
| [RCS-ERR-002](<https://rcs.zevarix.com/rules/types-and-errors/index.md#rcs-err-002--preserve-actionable-boundary-context>) | Advisory | Human review/tests | Diagnostic boundaries |
| [RCS-PROC-001](<https://rcs.zevarix.com/rules/processes-and-cancellation/index.md#rcs-proc-001--qualify-tools-and-use-structured-arguments>) | Required\* | Review/fake tools | Qualified structured process argv |
| [RCS-PROC-002](<https://rcs.zevarix.com/rules/processes-and-cancellation/index.md#rcs-proc-002--verify-process-outcomes-and-bounded-output>) | Required\* | Review/fake tools | Verify bounded process outcomes |
| [RCS-SAFE-001](<https://rcs.zevarix.com/rules/safety/index.md#rcs-safe-001--justify-unsafe-operations>) | Required\* | Review/tests | `unsafe` soundness |
| [RCS-DATA-001](<https://rcs.zevarix.com/rules/safety/index.md#rcs-data-001--protect-user-owned-data>) | Required\* | Review/tests | Non-destructive defaults |
| [RCS-FS-001](<https://rcs.zevarix.com/rules/mutable-effects/index.md#rcs-fs-001--recheck-mutable-filesystem-targets-before-consequential-effects>) | Required\* | Review/tests | Current file/target identity at effects |
| [RCS-PATH-001](<https://rcs.zevarix.com/rules/persistence-and-paths/index.md#rcs-path-001--do-not-confuse-pathname-text-with-filesystem-identity>) | Required\* | Review/tests | Native path representation vs physical identity |
| [RCS-DB-001](<https://rcs.zevarix.com/rules/persistence-and-paths/index.md#rcs-db-001--commit-related-state-transitions-atomically>) | Required\* | Review/tests | Atomic guarded SQLite transitions |
| [RCS-DB-002](<https://rcs.zevarix.com/rules/persistence-and-paths/index.md#rcs-db-002--qualify-the-live-schema-and-recovery-invariants>) | Required\* | Review/tests | Validate live SQLite enforcement schema |
| [RCS-STATE-001](<https://rcs.zevarix.com/rules/mutable-effects/index.md#rcs-state-001--do-not-register-an-effect-as-complete-before-verification>) | Required\* | Review/tests | Prove output before completion |
| [RCS-STATE-002](<https://rcs.zevarix.com/rules/mutable-effects/index.md#rcs-state-002--reconcile-uncertain-effects-before-retrying-them>) | Required\* | Review/tests | Reconcile ambiguous retry outcomes |
| [RCS-CANCEL-001](<https://rcs.zevarix.com/rules/processes-and-cancellation/index.md#rcs-cancel-001--separate-stop-requests-from-durable-effect-truth>) | Required\* | Review/tests | Stop requests versus effect truth |
| [RCS-CONC-001](<https://rcs.zevarix.com/rules/concurrency-and-tooling/index.md#rcs-conc-001--make-shared-state-invariants-atomic-at-the-right-boundary>) | Required\* | Review/contended tests | Atomic shared-state admission |
| [RCS-PERF-001](<https://rcs.zevarix.com/rules/performance/index.md#rcs-perf-001--review-work-across-call-paths>) | Required\* | Review/instrumentation | Avoid costly duplicate work |
| [RCS-PERF-002](<https://rcs.zevarix.com/rules/performance/index.md#rcs-perf-002--optimize-with-evidence>) | Advisory | Profiling/review | Avoid premature optimization |
| [RCS-PROGRESS-001](<https://rcs.zevarix.com/rules/observability/index.md#rcs-progress-001--keep-perceptibly-long-operations-observable>) | Required\* | Review/tests | Observable long-running work |
| [RCS-TERM-001](<https://rcs.zevarix.com/rules/observability/index.md#rcs-term-001--keep-terminal-presentation-recoverable-and-adaptable>) | Required\* | Review/tests | Recoverable terminal presentation |
| [RCS-LOG-001](<https://rcs.zevarix.com/rules/observability/index.md#rcs-log-001--emit-useful-bounded-and-safe-diagnostic-logs>) | Required\* | Review/tests | Safe bounded diagnostics |
| [RCS-TEST-001](<https://rcs.zevarix.com/rules/testing/index.md#rcs-test-001--make-tests-deterministic-and-owned>) | Required | Tests/review | Synthetic fixture isolation |
| [RCS-TEST-002](<https://rcs.zevarix.com/rules/testing/index.md#rcs-test-002--verify-real-failure-modes>) | Required\* | Tests/review | Negative-path coverage |
| [RCS-TEST-003](<https://rcs.zevarix.com/rules/testing/index.md#rcs-test-003--organize-tests-around-behavioral-contracts-and-named-cases>) | Advisory | Review | Behavioral tests with named cases |
| [RCS-TEST-004](<https://rcs.zevarix.com/rules/testing/index.md#rcs-test-004--verify-consequential-behavior-not-only-execution>) | Advisory | Focused tests/coverage/mutation review | Risk-weighted behavioral verification |
| [RCS-DOC-001](<https://rcs.zevarix.com/rules/testing/index.md#rcs-doc-001--document-nonobvious-contracts>) | Advisory | Rustdoc/review | Important invariants |
| [RCS-TOOL-001](<https://rcs.zevarix.com/rules/concurrency-and-tooling/index.md#rcs-tool-001--align-formatting-edition-and-lint-expectations>) | Advisory | rustfmt/Clippy/review | Align edition, format and lints |
| [RCS-TOOL-002](<https://rcs.zevarix.com/rules/concurrency-and-tooling/index.md#rcs-tool-002--test-the-supported-contract-not-a-convenient-subset>) | Required\* | CI/review | Validate actual supported targets |

**Required**\* means required when that rule's stated applicability condition holds (for example, user-owned data or a large-file hot path), not when an unrelated project feature is absent.

## Using these rules in a code review

Follow the [reviewer guide](<https://rcs.zevarix.com/review-guide/index.md>) to select applicable rule IDs, trace affected call paths, record evidence-backed findings, and separate correctness defects from optional suggestions. A consuming repository must explicitly adopt these rules (normally the latest `main`, or an intentional fixed revision) before they are binding requirements.

## Application

Review standards in proportion to the change. A library API and a private command-line module have different concerns; a one-time small string operation and repeated multi-gigabyte image hashing have different costs.

**Do not weaken** existing identity checks, concurrency guarantees, input validation, recovery proof or data-integrity constraints just to satisfy a performance or simplicity suggestion. Safety-critical patterns are useful as references but no external certification or unpublished preview is incorporated wholesale.

## Evidence and exceptions

When a rule warrants an actionable finding, record **ID → path/symbol → concrete trigger → consequence → smallest safe fix/test**. Label stylistic suggestions separately.

An adopting project may explain an exception inline near the code or in its own rules/ADR. A documented exception must still satisfy the project's actual functional and safety contracts. A large but cohesive module can be entirely acceptable; numerical file-size or method-count limits are not part of these standards.

See [Sources and attribution](<https://rcs.zevarix.com/sources/index.md>) for upstream materials and attribution.
