style(rust): document declaration ordering

This commit is contained in:
2026-09-19 10:29:05 -04:00
parent efb2fd3234
commit 5190d1ed01
3 changed files with 29 additions and 15 deletions

View File

@@ -0,0 +1,14 @@
# Declaration rules
## Order declarations by use
### Rule
Order related Rust declarations from the type that uses other local types to those local dependencies.
For a type with multiple local field dependencies, place dependencies in field order.
Apply the rule depth-first before moving to the next dependency.
### Rationale
Use-first order lets readers start with the public or owning shape.
They can then read supporting types in the order the owner references them.

View File

@@ -1,14 +1,5 @@
use std::path::PathBuf;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct FileId(usize);
#[derive(Debug)]
pub struct SourceFile {
pub path: PathBuf,
pub source: String,
}
#[derive(Debug, Default)]
pub struct FileStore {
files: Vec<SourceFile>,
@@ -31,3 +22,12 @@ impl From<Vec<SourceFile>> for FileStore {
Self { files }
}
}
#[derive(Debug)]
pub struct SourceFile {
pub path: PathBuf,
pub source: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct FileId(usize);

View File

@@ -6,6 +6,12 @@ use crate::rules::empty_inherit::EmptyInherit;
pub mod deprecated_to_path;
pub mod empty_inherit;
#[derive(Debug)]
pub struct Diagnostic {
pub file_id: FileId,
pub finding: Finding,
}
#[derive(Debug)]
pub struct Finding {
pub rule_id: &'static str,
@@ -13,12 +19,6 @@ pub struct Finding {
pub message: &'static str,
}
#[derive(Debug)]
pub struct Diagnostic {
pub file_id: FileId,
pub finding: Finding,
}
impl std::fmt::Display for Diagnostic {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(