Skip to main content

SymbolPathResolver

Struct SymbolPathResolver 

Source
pub struct SymbolPathResolver { /* private fields */ }
Expand description

Resolves WorkspaceFilePath to SymbolPath

§Design

This resolver centralizes the conversion from file paths to Rust symbol paths. It wraps the crate name and layout, providing methods for bidirectional conversion between file paths and symbol paths.

§Example

// For a crate in crates/ directory
let resolver = SymbolPathResolver::with_layout(
    "my_crate",
    CrateLayout::in_crates("my-crate"),
);

// Module path from file
let module = resolver.resolve_module(&file_path)?;
// → my_crate::foo::bar

// Reverse: symbol to file
let file = resolver.to_workspace_file_path(&symbol, &workspace_root);
// → crates/my-crate/src/foo/bar.rs

Implementations§

Source§

impl SymbolPathResolver

Source

pub fn new(crate_name: impl AsRef<str>) -> Self

Create a resolver for a crate (assumes Root layout and Lib entry point)

For workspace crates in crates/ directory, use with_layout instead.

Source

pub fn with_layout(crate_name: impl AsRef<str>, layout: CrateLayout) -> Self

Create a resolver with explicit layout (assumes Lib entry point)

§Example
// For crates/my-crate/src/*.rs
let resolver = SymbolPathResolver::with_layout(
    "my_crate",
    CrateLayout::in_crates("my-crate"),
);
Source

pub fn with_layout_and_entry( crate_name: impl AsRef<str>, layout: CrateLayout, entry_point: EntryPoint, ) -> Self

Create a resolver with explicit layout and entry point

§Example
// For a binary crate: crates/my-crate/src/main.rs
let resolver = SymbolPathResolver::with_layout_and_entry(
    "my_crate",
    CrateLayout::in_crates("my-crate"),
    EntryPoint::Bin,
);
Source

pub fn from_crate_name(crate_name: CrateName) -> Self

Create a resolver from a CrateName (assumes Root layout and Lib entry point)

Source

pub fn from_crate_name_with_layout( crate_name: CrateName, layout: CrateLayout, ) -> Self

Create a resolver from a CrateName with explicit layout (assumes Lib entry point)

Source

pub fn from_crate_name_with_layout_and_entry( crate_name: CrateName, layout: CrateLayout, entry_point: EntryPoint, ) -> Self

Create a resolver from a CrateName with explicit layout and entry point

Source

pub fn from_workspace_path(path: &WorkspaceFilePath) -> Result<Self, ParseError>

Create a resolver from a WorkspaceFilePath

Extracts the crate name and infers both layout and entry point from the file path.

Source

pub fn crate_name(&self) -> &CrateName

Get the crate name

Source

pub fn entry_point(&self) -> EntryPoint

Get the entry point

Source

pub fn layout(&self) -> &CrateLayout

Get the crate layout

Source

pub fn resolve_module( &self, path: &WorkspaceFilePath, ) -> Result<SymbolPath, ParseError>

Resolve file path to module path (SymbolPath)

e.g., “src/foo/bar.rs” → “my_crate::foo::bar”

Source

pub fn resolve_item( &self, path: &WorkspaceFilePath, item_name: &str, ) -> Result<SymbolPath, ParseError>

Resolve item in file

e.g., “src/lib.rs” + “MyStruct” → “my_crate::MyStruct”

Source

pub fn resolve_nested( &self, path: &WorkspaceFilePath, segments: &[&str], ) -> Result<SymbolPath, ParseError>

Resolve nested item in file

e.g., “src/lib.rs” + [“Foo”, “new”] → “my_crate::Foo::new”

Source

pub fn module_path_str(&self, path: &WorkspaceFilePath) -> String

Get module path string (without parsing to SymbolPath)

Useful when you need the string representation directly.

Source

pub fn to_workspace_file_path( &self, symbol_path: &SymbolPath, workspace_root: Arc<Path>, ) -> WorkspaceFilePath

Convert SymbolPath to WorkspaceFilePath (reverse of resolve_module)

Determines the file path where a symbol should be defined.

§Rules
  • cratesrc/lib.rs
  • crate::Itemsrc/lib.rs (item in crate root)
  • crate::foo::Itemsrc/foo.rs (item in module foo)
  • crate::foo::bar::Itemsrc/foo/bar.rs (item in nested module)
§Arguments
  • path: The symbol path to convert
  • workspace_root: The workspace root for creating WorkspaceFilePath
§Example
let resolver = SymbolPathResolver::new("my_crate");
let symbol = SymbolPath::parse("my_crate::models::User")?;
let file = resolver.to_workspace_file_path(&symbol, &workspace_root);
// → src/models.rs
Source

pub fn symbol_path_to_relative(&self, symbol_path: &SymbolPath) -> String

Convert SymbolPath to relative file path string

This is the core logic for reverse conversion. Uses the crate layout and entry point to determine the correct path.

Trait Implementations§

Source§

impl Clone for SymbolPathResolver

Source§

fn clone(&self) -> SymbolPathResolver

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SymbolPathResolver

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.