pub struct WorkspaceGraph { /* private fields */ }Expand description
Workspace dependency graph.
Built from cargo_metadata, using petgraph for efficient traversals.
Implementations§
Source§impl WorkspaceGraph
impl WorkspaceGraph
Sourcepub fn from_metadata(metadata: &Metadata) -> RailResult<Self>
pub fn from_metadata(metadata: &Metadata) -> RailResult<Self>
Load workspace graph from cargo metadata.
§Performance
- Graph construction: 10-50ms
- Path cache: built eagerly (10-50ms)
- Does not reload metadata (use existing from CargoState)
Sourcepub fn workspace_members(&self) -> &[String]
pub fn workspace_members(&self) -> &[String]
Get all workspace member crate names (pre-sorted).
Sourcepub fn transitive_dependents(&self, crate_name: &str) -> RailResult<Vec<String>>
pub fn transitive_dependents(&self, crate_name: &str) -> RailResult<Vec<String>>
Get transitive reverse dependencies (all workspace crates that depend on this one).
Uses petgraph DFS for efficient traversal.
§Performance
O(V + E) where V = vertices, E = edges. Typically <10ms for <100 crates.
Sourcepub fn transitive_dependents_of_set(
&self,
crate_names: &HashSet<String>,
) -> RailResult<HashSet<String>>
pub fn transitive_dependents_of_set( &self, crate_names: &HashSet<String>, ) -> RailResult<HashSet<String>>
Get transitive reverse dependencies for multiple crates in a single traversal.
This is more efficient than calling transitive_dependents() multiple times
when you have many direct crates, as it does a single O(V+E) traversal instead
of O(N × (V+E)) where N is the number of crates.
§Performance
O(V + E) regardless of input set size. Significantly faster than N separate traversals for large input sets.
Sourcepub fn publish_order(&self) -> RailResult<Vec<String>>
pub fn publish_order(&self) -> RailResult<Vec<String>>
Get workspace members in dependency order (dependencies first, dependents last).
Returns crates in the order they should be published: a crate’s dependencies are always published before the crate itself.
Uses topological sort on the dependency graph to ensure correct ordering.
§Errors
Returns error if circular dependencies are detected (should never happen with Cargo).
§Performance
O(V + E) where V = vertices, E = edges. Typically <10ms for <100 crates.
Sourcepub fn file_to_crate(&self, file_path: &Path) -> Option<String>
pub fn file_to_crate(&self, file_path: &Path) -> Option<String>
Map a file path to its owning crate.
O(1) lookups using pre-built path cache. Filters out VCS directories (.git, .jj) and other non-source paths.
Accepts both:
- Workspace-relative paths (e.g., “crates/foo/src/lib.rs”)
- Absolute paths (will be converted to workspace-relative)
Works for deleted files - does not require the file to exist on disk.
Auto Trait Implementations§
impl !Freeze for WorkspaceGraph
impl RefUnwindSafe for WorkspaceGraph
impl Send for WorkspaceGraph
impl Sync for WorkspaceGraph
impl Unpin for WorkspaceGraph
impl UnwindSafe for WorkspaceGraph
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> 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