pub struct DependencyGraphBuilder { /* private fields */ }Expand description
Coordinates dependency extraction across multiple languages to build a unified dependency graph.
The builder uses language-specific extractors to parse import/dependency
statements and progressively constructs a DependencyGraph. It manages
the storage backend for persistence and provides batch processing capabilities.
§Usage Pattern
- Create builder with storage backend
- Extract files using
extract_file()orextract_files() - Access graph with
graph() - Optionally persist with
persist()
§Examples
let storage = Box::new(InMemoryStorage::new());
let mut builder = DependencyGraphBuilder::new(storage);
// Extract single file
builder.extract_file(std::path::Path::new("src/main.rs")).await?;
// Batch extraction
let files = vec![
std::path::PathBuf::from("src/utils.rs"),
std::path::PathBuf::from("src/config.ts"),
];
builder.extract_files(&files).await?;
// Access graph
println!("Graph has {} nodes", builder.graph().node_count());
// Persist to storage
builder.persist().await?;Implementations§
Source§impl DependencyGraphBuilder
impl DependencyGraphBuilder
Sourcepub fn new(storage: Box<dyn StorageBackend>) -> Self
pub fn new(storage: Box<dyn StorageBackend>) -> Self
Creates a new dependency graph builder with the given storage backend.
§Arguments
storage- Storage backend for persisting fingerprints and graph data
§Examples
use thread_flow::incremental::dependency_builder::DependencyGraphBuilder;
use thread_flow::incremental::storage::InMemoryStorage;
let storage = Box::new(InMemoryStorage::new());
let builder = DependencyGraphBuilder::new(storage);Sourcepub fn graph(&self) -> &DependencyGraph
pub fn graph(&self) -> &DependencyGraph
Accesses the built dependency graph.
Returns a reference to the DependencyGraph constructed from
all extracted files.
§Examples
let storage = Box::new(InMemoryStorage::new());
let builder = DependencyGraphBuilder::new(storage);
let graph = builder.graph();
assert_eq!(graph.node_count(), 0); // Empty graph initiallySourcepub async fn extract_file(&mut self, file_path: &Path) -> Result<(), BuildError>
pub async fn extract_file(&mut self, file_path: &Path) -> Result<(), BuildError>
Extracts dependencies from a single file.
Detects the file’s language, uses the appropriate extractor, and adds the resulting edges to the dependency graph.
§Arguments
file_path- Path to the source file to analyze
§Errors
Returns an error if:
- The file’s language is not supported
- The file cannot be read
- Dependency extraction fails
§Examples
let storage = Box::new(InMemoryStorage::new());
let mut builder = DependencyGraphBuilder::new(storage);
builder.extract_file(std::path::Path::new("src/main.rs")).await?;Sourcepub async fn extract_files(
&mut self,
files: &[PathBuf],
) -> Result<(), BuildError>
pub async fn extract_files( &mut self, files: &[PathBuf], ) -> Result<(), BuildError>
Extracts dependencies from multiple files in batch.
Processes all files and continues on individual extraction failures. Returns an error only if all extractions fail.
§Arguments
files- Slice of file paths to analyze
§Errors
Returns the last error encountered if ANY extraction fails. Individual extraction errors are logged as warnings.
§Examples
let storage = Box::new(InMemoryStorage::new());
let mut builder = DependencyGraphBuilder::new(storage);
let files = vec![
std::path::PathBuf::from("src/main.rs"),
std::path::PathBuf::from("src/lib.rs"),
];
builder.extract_files(&files).await?;Sourcepub async fn persist(&self) -> Result<(), BuildError>
pub async fn persist(&self) -> Result<(), BuildError>
Persists the dependency graph to the storage backend.
Saves all fingerprints and edges to the configured storage.
§Errors
Returns an error if storage operations fail.
§Examples
let storage = Box::new(InMemoryStorage::new());
let mut builder = DependencyGraphBuilder::new(storage);
// ... extract files ...
// Persist to storage
builder.persist().await?;Auto Trait Implementations§
impl Freeze for DependencyGraphBuilder
impl !RefUnwindSafe for DependencyGraphBuilder
impl Send for DependencyGraphBuilder
impl Sync for DependencyGraphBuilder
impl Unpin for DependencyGraphBuilder
impl UnsafeUnpin for DependencyGraphBuilder
impl !UnwindSafe for DependencyGraphBuilder
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