diff options
Diffstat (limited to 'mingling_pathf')
| -rw-r--r-- | mingling_pathf/src/error.rs | 31 | ||||
| -rw-r--r-- | mingling_pathf/src/module_pathf.rs | 10 | ||||
| -rw-r--r-- | mingling_pathf/src/patterns.rs | 4 | ||||
| -rw-r--r-- | mingling_pathf/src/patterns/chain.rs | 9 | ||||
| -rw-r--r-- | mingling_pathf/src/patterns/completion.rs | 9 | ||||
| -rw-r--r-- | mingling_pathf/src/patterns/help.rs | 9 | ||||
| -rw-r--r-- | mingling_pathf/src/patterns/pack.rs | 22 | ||||
| -rw-r--r-- | mingling_pathf/src/patterns/renderer.rs | 9 |
8 files changed, 47 insertions, 56 deletions
diff --git a/mingling_pathf/src/error.rs b/mingling_pathf/src/error.rs index 025ceed..513ec23 100644 --- a/mingling_pathf/src/error.rs +++ b/mingling_pathf/src/error.rs @@ -24,10 +24,7 @@ pub enum MinglingPathfinderError { /// /// `file` is the file containing the invalid attribute. /// `path_attr` is the value of the `#[path]` attribute. - PathPointsOutside { - file: PathBuf, - path_attr: String, - }, + PathPointsOutside { file: PathBuf, path_attr: String }, /// No entry point file (`main.rs`, `lib.rs`, or any file under `bin/`) was found. NoEntryPointFound, @@ -36,23 +33,33 @@ pub enum MinglingPathfinderError { /// /// `path` is the file that failed to parse. /// `message` contains details from the parser. - SynError { - path: PathBuf, - message: String, - }, + SynError { path: PathBuf, message: String }, } impl fmt::Display for MinglingPathfinderError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::IoError(e) => write!(f, "IO error: {e}"), - Self::ModuleNotFound { parent, module_name } => { - write!(f, "Module `{module_name}` not found relative to {}", parent.display()) + Self::ModuleNotFound { + parent, + module_name, + } => { + write!( + f, + "Module `{module_name}` not found relative to {}", + parent.display() + ) } Self::PathPointsOutside { file, path_attr } => { - write!(f, "#[path = \"{path_attr}\"] in {} points outside the project", file.display()) + write!( + f, + "#[path = \"{path_attr}\"] in {} points outside the project", + file.display() + ) + } + Self::NoEntryPointFound => { + write!(f, "No entry point found (main.rs, lib.rs, or bin/*.rs)") } - Self::NoEntryPointFound => write!(f, "No entry point found (main.rs, lib.rs, or bin/*.rs)"), Self::SynError { path, message } => { write!(f, "Failed to parse {}: {message}", path.display()) } diff --git a/mingling_pathf/src/module_pathf.rs b/mingling_pathf/src/module_pathf.rs index d06be9b..c20fd82 100644 --- a/mingling_pathf/src/module_pathf.rs +++ b/mingling_pathf/src/module_pathf.rs @@ -10,7 +10,6 @@ use crate::error::MinglingPathfinderError; /// effective module path (e.g., `crate::foo::bar`). #[derive(Debug, Clone)] pub struct MappingItem { - /// The path of the source file (relative to the crate root, with `./` prefix). file_path: PathBuf, @@ -349,11 +348,7 @@ fn propagate_children(parent_file: &Path, ctx: &mut Context) { .cloned() .unwrap_or_else(|| "crate".to_string()); - let reexported = ctx - .reexports - .get(parent_file) - .cloned() - .unwrap_or_default(); + let reexported = ctx.reexports.get(parent_file).cloned().unwrap_or_default(); let Some(children) = ctx.children.get(parent_file).cloned() else { return; @@ -367,8 +362,7 @@ fn propagate_children(parent_file: &Path, ctx: &mut Context) { format!("{}::{}", parent_effective, child.name) }; - ctx.effective_paths - .insert(child.file.clone(), effective); + ctx.effective_paths.insert(child.file.clone(), effective); propagate_children(&child.file, ctx); } } diff --git a/mingling_pathf/src/patterns.rs b/mingling_pathf/src/patterns.rs index b3e0cd3..d0bda5d 100644 --- a/mingling_pathf/src/patterns.rs +++ b/mingling_pathf/src/patterns.rs @@ -3,8 +3,8 @@ pub use chain::*; pub use completion::*; pub use dispatcher::*; pub use dispatcher_clap::*; -pub use groupped_derive::*; pub use group::*; +pub use groupped_derive::*; pub use help::*; pub use pack::*; pub use renderer::*; @@ -14,8 +14,8 @@ mod chain; mod completion; mod dispatcher; mod dispatcher_clap; -mod groupped_derive; mod group; +mod groupped_derive; mod help; mod pack; mod renderer; diff --git a/mingling_pathf/src/patterns/chain.rs b/mingling_pathf/src/patterns/chain.rs index 10d698e..d64ed3b 100644 --- a/mingling_pathf/src/patterns/chain.rs +++ b/mingling_pathf/src/patterns/chain.rs @@ -63,10 +63,7 @@ fn collect_from_item(item: &Item, current_mod: &str, items: &mut Vec<AnalyzeItem } fn has_attr(attrs: &[syn::Attribute], name: &str) -> bool { - attrs.iter().any(|a| { - a.path() - .segments - .last() - .is_some_and(|s| s.ident == name) - }) + attrs + .iter() + .any(|a| a.path().segments.last().is_some_and(|s| s.ident == name)) } diff --git a/mingling_pathf/src/patterns/completion.rs b/mingling_pathf/src/patterns/completion.rs index 7e4cd09..ff20e0f 100644 --- a/mingling_pathf/src/patterns/completion.rs +++ b/mingling_pathf/src/patterns/completion.rs @@ -56,10 +56,7 @@ fn collect_from_item(item: &Item, current_mod: &str, items: &mut Vec<AnalyzeItem } fn has_attr(attrs: &[syn::Attribute], name: &str) -> bool { - attrs.iter().any(|a| { - a.path() - .segments - .last() - .is_some_and(|s| s.ident == name) - }) + attrs + .iter() + .any(|a| a.path().segments.last().is_some_and(|s| s.ident == name)) } diff --git a/mingling_pathf/src/patterns/help.rs b/mingling_pathf/src/patterns/help.rs index 357626b..02bfa4f 100644 --- a/mingling_pathf/src/patterns/help.rs +++ b/mingling_pathf/src/patterns/help.rs @@ -56,10 +56,7 @@ fn collect_from_item(item: &Item, current_mod: &str, items: &mut Vec<AnalyzeItem } fn has_attr(attrs: &[syn::Attribute], name: &str) -> bool { - attrs.iter().any(|a| { - a.path() - .segments - .last() - .is_some_and(|s| s.ident == name) - }) + attrs + .iter() + .any(|a| a.path().segments.last().is_some_and(|s| s.ident == name)) } diff --git a/mingling_pathf/src/patterns/pack.rs b/mingling_pathf/src/patterns/pack.rs index f025f7d..83c1cee 100644 --- a/mingling_pathf/src/patterns/pack.rs +++ b/mingling_pathf/src/patterns/pack.rs @@ -40,12 +40,13 @@ impl AnalyzePattern for PackPattern { if let Some((_, nested)) = &item_mod.content { for n in nested { if let Item::Macro(m) = n - && let Some(name) = try_extract_pack_name(m) { - items.push(AnalyzeItem { - module: item_mod.ident.to_string(), - item_name: name, - }); - } + && let Some(name) = try_extract_pack_name(m) + { + items.push(AnalyzeItem { + module: item_mod.ident.to_string(), + item_name: name, + }); + } } } } @@ -89,10 +90,11 @@ fn try_extract_pack_name(m: &syn::ItemMacro) -> Option<String> { // Check if `=` follows if let Some(proc_macro2::TokenTree::Punct(p)) = iter.next() - && p.as_char() == '=' { - // pack!(TypeName = InnerType) - return Some(type_name); - } + && p.as_char() == '=' + { + // pack!(TypeName = InnerType) + return Some(type_name); + } // pack_err!(TypeName) — only a single ident return Some(type_name); diff --git a/mingling_pathf/src/patterns/renderer.rs b/mingling_pathf/src/patterns/renderer.rs index 410ae14..054769e 100644 --- a/mingling_pathf/src/patterns/renderer.rs +++ b/mingling_pathf/src/patterns/renderer.rs @@ -56,10 +56,7 @@ fn collect_from_item(item: &Item, current_mod: &str, items: &mut Vec<AnalyzeItem } fn has_attr(attrs: &[syn::Attribute], name: &str) -> bool { - attrs.iter().any(|a| { - a.path() - .segments - .last() - .is_some_and(|s| s.ident == name) - }) + attrs + .iter() + .any(|a| a.path().segments.last().is_some_and(|s| s.ident == name)) } |
