From 7a597044d3cf260a3b5c4fc119e2f432b8c0504c Mon Sep 17 00:00:00 2001 From: alexion Date: Sat, 19 Sep 2026 17:31:50 -0400 Subject: [PATCH] docs(rust-style): order declarations by dependency --- src/skills/style/rust/rules/declarations.md | 38 +++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/skills/style/rust/rules/declarations.md diff --git a/src/skills/style/rust/rules/declarations.md b/src/skills/style/rust/rules/declarations.md new file mode 100644 index 0000000..4e337c7 --- /dev/null +++ b/src/skills/style/rust/rules/declarations.md @@ -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, +} + +struct FileStore { + files: Vec, +} + +struct SourceFile { + path: PathBuf, + source: String, +} + +struct Diagnostic { + message: String, +} +```