PathResolver

Struct PathResolver 

Source
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

Source

pub fn new(canonical_path: &str) -> Option<Self>

Create a new path resolver for a specific canonical path.

§Arguments
  • canonical_path - The fully qualified path (e.g., “crate::compiler::types::IRValue”)
§Returns

A new PathResolver, or None if the path is invalid

§Example
let resolver = PathResolver::new("crate::compiler::types::IRValue");
Source

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.

Source

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().

Source

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:

  1. Exact canonical path match
  2. Import alias resolution
  3. Module path resolution
§Arguments
  • path - The syn::Path to check
§Returns

true if the path definitely refers to our target

Source

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 check
  • preceding_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

Source

pub fn target_name(&self) -> &str

Get the simple name of the target.

Source

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

Source§

fn clone(&self) -> PathResolver

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PathResolver

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.