pub struct PathResolver { /* private fields */ }Expand description
Tracks use statements and validates whether paths refer to a specific target.
This is generic enough to work for enums, structs, functions, traits, etc.
Implementations§
Source§impl PathResolver
impl PathResolver
Sourcepub fn simple(name: &str) -> Self
pub fn simple(name: &str) -> Self
Create a resolver that only matches exact simple paths (backward compatible mode).
This matches the old behavior where only EnumName::Variant is matched,
without any use statement tracking.
Sourcepub fn scan_file(&mut self, file: &File)
pub fn scan_file(&mut self, file: &File)
Scan a file to build the local alias map from use statements.
This should be called once per file before using matches_target().
Sourcepub fn matches_target(&self, path: &Path) -> bool
pub fn matches_target(&self, path: &Path) -> bool
Check if a path definitely refers to our target.
This uses conservative matching - only returns true if we’re certain the path refers to our target based on:
- Exact canonical path match
- Import alias resolution
- Module path resolution
§Arguments
path- The syn::Path to check
§Returns
true if the path definitely refers to our target
Sourcepub fn path_ends_with(&self, path: &Path, preceding_segment: &str) -> bool
pub fn path_ends_with(&self, path: &Path, preceding_segment: &str) -> bool
Check if a path ends with the preceding segment (e.g., enum name).
This is useful for matching patterns like EnumName::VariantName
regardless of what the variant name is, when combined with path validation.
§Arguments
path- The path to checkpreceding_segment- The segment before the variant (e.g., “IRValue” for enum variants)
§Returns
true if the path has at least 2 segments and the second-to-last matches preceding_segment
Sourcepub fn target_name(&self) -> &str
pub fn target_name(&self) -> &str
Get the simple name of the target.
Sourcepub fn might_match_via_glob(&self, path: &Path) -> bool
pub fn might_match_via_glob(&self, path: &Path) -> bool
Check if a path could potentially match via glob import.
Returns true if:
- We found a glob import that could include our target
- The path’s simple name matches our target
Trait Implementations§
Source§impl Clone for PathResolver
impl Clone for PathResolver
Source§fn clone(&self) -> PathResolver
fn clone(&self) -> PathResolver
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more