Add support for sorting named struct fields.
diff --git a/src/check.rs b/src/check.rs
index 281c052..1b50442 100644
--- a/src/check.rs
+++ b/src/check.rs
@@ -1,5 +1,5 @@
use syn::{Arm, Ident, Result, Variant};
-use syn::{Error, Pat, PatIdent};
+use syn::{Error, Field, Fields, Pat, PatIdent};
use crate::compare::Path;
use crate::format;
@@ -8,6 +8,13 @@
pub fn sorted(input: Input) -> Result<()> {
let paths = match input {
Enum(item) => collect_paths(item.variants)?,
+ Struct(item) => {
+ if let Fields::Named(fields) = item.fields {
+ collect_paths(fields.named)?
+ } else {
+ unreachable!("must be named field")
+ }
+ }
Match(expr) | Let(expr) => collect_paths(expr.arms)?,
};
@@ -44,6 +51,14 @@
}
}
+impl IntoPath for Field {
+ fn into_path(self) -> Result<Path> {
+ Ok(Path {
+ segments: vec![self.ident.expect("must be named field")],
+ })
+ }
+}
+
impl IntoPath for Arm {
fn into_path(self) -> Result<Path> {
// Sort by just the first pat.