For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /packs/languages/rust/file-structure.md.
Quick start

File structure

Assign code to the narrowest capability that owns it.

Crates and modules

Why

Domain logic should not need a binary's terminal presentation to inspect a value.

Rules

  • MUST separate reusable library behavior from binary presentation and resource adapters. [review]
  • MUST use Cargo workspaces when the repository owns multiple related crates. [review]
  • MUST keep lib.rs and main.rs entrypoints small and deliberate. [review]
  • MUST expose only the supported public surface; prefer private or pub(crate) items internally. [review]
  • MUST name modules for domain responsibilities rather than catch-all helpers. [review]
  • MUST use explicit imports and re-exports rather than wildcard API surfaces. [review]
  • MUST keep tests beside their capability or in the owning crate's integration tests. [review]

[review]

Cargo and the compiler validate module boundaries. Review checks ownership, public visibility, and entrypoint scope.

Enforcement

Cargo and the compiler validate module boundaries. Review checks ownership, public visibility, and entrypoint scope.