aboutsummaryrefslogtreecommitdiff
path: root/mingling_pathf/src/module_pathf.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-10 16:30:20 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-10 16:30:20 +0800
commit03b487f0f93ac32835149d4c1a0fb420341134f8 (patch)
tree80e3e901c054581dcffc09da471053d15eb12560 /mingling_pathf/src/module_pathf.rs
parent1be60c990f27cd9006fa3db8aa5bd623c33840e8 (diff)
feat(pathf): enforce pedantic lints and update API ergonomics
- Add `#[must_use]` to public constructors and getters - Change `init_with_config` to accept `&PathfinderConfig` instead of owned value - Refactor `map_or_else` and `or_insert_with` for clippy compliance - Add `#![deny(clippy::pedantic)]` and `#![deny(clippy::nursery)]` - Document error cases in public API docs - Simplify duplicated dispatcher_clap analysis logic
Diffstat (limited to 'mingling_pathf/src/module_pathf.rs')
-rw-r--r--mingling_pathf/src/module_pathf.rs17
1 files changed, 11 insertions, 6 deletions
diff --git a/mingling_pathf/src/module_pathf.rs b/mingling_pathf/src/module_pathf.rs
index f0a06d1..ebb7979 100644
--- a/mingling_pathf/src/module_pathf.rs
+++ b/mingling_pathf/src/module_pathf.rs
@@ -25,11 +25,13 @@ pub struct MappingItem {
impl MappingItem {
/// Returns the path of the source file (relative to the crate root, with `./` prefix).
+ #[must_use]
pub fn file_path(&self) -> &Path {
&self.file_path
}
/// Returns the effective module path corresponding to this file (e.g., `"crate::foo::bar"`).
+ #[must_use]
pub fn module_path(&self) -> &str {
&self.module_path
}
@@ -50,6 +52,12 @@ pub struct ModulePathMapping {
/// Analyzes the module structure of a crate and returns the effective module path for each source file.
///
/// `crate_dir` is the crate root directory (i.e., the directory containing `Cargo.toml`).
+///
+/// # Errors
+///
+/// Returns an error if the `src/` directory does not exist, no entry point file is found,
+/// a source file cannot be read or parsed, a child module file cannot be resolved, or
+/// an I/O error occurs while traversing the crate directory.
pub fn analyze(crate_dir: &Path) -> Result<ModulePathMapping, MinglingPathfinderError> {
let src_dir = crate_dir.join("src");
if !src_dir.is_dir() {
@@ -121,11 +129,8 @@ impl Context {
}
fn relative_path(&self, abs: &Path) -> PathBuf {
- if let Ok(rel) = abs.strip_prefix(&self.crate_dir) {
- PathBuf::from("./").join(rel)
- } else {
- abs.to_path_buf()
- }
+ abs.strip_prefix(&self.crate_dir)
+ .map_or_else(|_| abs.to_path_buf(), |rel| PathBuf::from("./").join(rel))
}
}
@@ -276,7 +281,7 @@ fn collect_reexports(tree: &UseTree, results: &mut Vec<String>) {
UseTree::Rename(rename) => {
results.push(rename.ident.to_string());
}
- _ => {}
+ UseTree::Glob(_) => {}
}
}