diff --git a/src/skills/style/rust/rules/declarations.md b/src/skills/style/rust/rules/declarations.md new file mode 100644 index 0000000..acf9279 --- /dev/null +++ b/src/skills/style/rust/rules/declarations.md @@ -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. diff --git a/src/xatu/file_store.rs b/src/xatu/file_store.rs index f36cd14..ef2aafe 100644 --- a/src/xatu/file_store.rs +++ b/src/xatu/file_store.rs @@ -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, @@ -31,3 +22,12 @@ impl From> 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); diff --git a/src/xatu/rules.rs b/src/xatu/rules.rs index 567e660..fb71597 100644 --- a/src/xatu/rules.rs +++ b/src/xatu/rules.rs @@ -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!(