docs(rust-style): order declarations by dependency

This commit was merged in pull request #82.
This commit is contained in:
2026-09-19 17:31:50 -04:00
parent 87dc93513b
commit ad00301ac9
3 changed files with 111 additions and 71 deletions

View File

@@ -0,0 +1,38 @@
# Declaration rules
## Order declarations by dependency
### Rule
Order Rust declarations in depth-first dependency order.
Place each function, struct, and enum before private declarations that support it.
For structs and enums, order supporting declarations by field or variant order.
For functions, order helper declarations by first use in the function body.
Apply the same rule recursively to each supporting declaration.
### Rationale
Dependency order lets readers start at the public operation or type.
Readers can then continue downward into the declarations that explain each part.
### Examples
```rust
pub struct Report {
files: FileStore,
diagnostics: Vec<Diagnostic>,
}
struct FileStore {
files: Vec<SourceFile>,
}
struct SourceFile {
path: PathBuf,
source: String,
}
struct Diagnostic {
message: String,
}
```