pub struct RustDependencyExtractor { /* private fields */ }Expand description
Extracts Rust import and export dependencies using tree-sitter AST traversal.
Uses tree-sitter’s Rust grammar to parse use and pub use declarations
without executing Rust code. Thread-safe and reusable across files.
§Architecture
The extractor operates in two phases:
- Parse: Tree-sitter parses the source into an AST
- Walk: Recursive traversal extracts
use_declarationnodes and their nested structure (scoped identifiers, use lists, wildcards, aliases)
Module path resolution (converting "crate::config" to "src/config.rs")
is handled separately by resolve_module_path.
Implementations§
Source§impl RustDependencyExtractor
impl RustDependencyExtractor
Sourcepub fn extract_imports(
&self,
source: &str,
_file_path: &Path,
) -> Result<Vec<RustImportInfo>, ExtractionError>
pub fn extract_imports( &self, source: &str, _file_path: &Path, ) -> Result<Vec<RustImportInfo>, ExtractionError>
Extracts all use declarations from Rust source code.
Parses the source with tree-sitter and walks the AST to find all
use_declaration nodes. Both public and private use statements are
returned as imports (the caller may filter by visibility if needed).
§Arguments
source- Rust source code to analyze._file_path- Path of the source file (reserved for error context).
§Returns
A vector of RustImportInfo records, one per use declaration.
§Errors
Returns ExtractionError::ParseError if tree-sitter cannot parse
the source.
Sourcepub fn extract_exports(
&self,
source: &str,
_file_path: &Path,
) -> Result<Vec<ExportInfo>, ExtractionError>
pub fn extract_exports( &self, source: &str, _file_path: &Path, ) -> Result<Vec<ExportInfo>, ExtractionError>
Extracts all pub use re-export declarations from Rust source code.
Only public or restricted-visibility use statements are returned.
§Arguments
source- Rust source code to analyze._file_path- Path of the source file (reserved for error context).
§Returns
A vector of ExportInfo records, one per re-exported symbol.
For pub use types::{Config, Settings}, two records are returned.
§Errors
Returns ExtractionError::ParseError if tree-sitter cannot parse
the source.
Sourcepub fn resolve_module_path(
&self,
source_file: &Path,
module_path: &str,
) -> Result<PathBuf, ExtractionError>
pub fn resolve_module_path( &self, source_file: &Path, module_path: &str, ) -> Result<PathBuf, ExtractionError>
Resolves a Rust module path to a filesystem path.
Handles the three Rust-specific path prefixes:
crate::- resolves from thesrc/root of the cratesuper::- resolves from the parent module directoryself::- resolves from the current module directory
External crate paths (e.g., std::collections) cannot be resolved
to local files and return an error.
§Arguments
source_file- The file containing theusestatement.module_path- The module path (e.g.,"crate::config","super::utils").
§Returns
The resolved filesystem path to the target module file (e.g., src/config.rs).
§Errors
Returns ExtractionError::ResolutionError if:
- The path is an external crate (no
crate::,super::, orself::prefix) - The source file has no parent directory for
super::resolution
Sourcepub fn extract_dependency_edges(
&self,
source: &str,
file_path: &Path,
) -> Result<Vec<DependencyEdge>, ExtractionError>
pub fn extract_dependency_edges( &self, source: &str, file_path: &Path, ) -> Result<Vec<DependencyEdge>, ExtractionError>
Extract [DependencyEdge] values from a Rust source file.
Combines import extraction with path resolution to produce edges suitable for the incremental dependency graph. Only resolvable internal imports produce edges; external crates are silently skipped.
§Errors
Returns an error if the source file cannot be parsed.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RustDependencyExtractor
impl RefUnwindSafe for RustDependencyExtractor
impl Send for RustDependencyExtractor
impl Sync for RustDependencyExtractor
impl Unpin for RustDependencyExtractor
impl UnsafeUnpin for RustDependencyExtractor
impl UnwindSafe for RustDependencyExtractor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more