pub struct DependencyGraph { /* private fields */ }Expand description
A dependency graph of all injectable types in the application.
The graph is constructed from metadata generated by the proc macros and is validated once at container build time. After validation, the graph is not used during runtime resolution — providers resolve dependencies through static dispatch.
§Construction
The graph is typically built automatically by the container builder:
let graph = DependencyGraph::new(vec![
GraphNode::new("UserService", &["Database", "Cache"]),
GraphNode::leaf("Database"),
GraphNode::leaf("Cache"),
]);
graph.validate()?;Implementations§
Source§impl DependencyGraph
impl DependencyGraph
Sourcepub fn empty() -> DependencyGraph
pub fn empty() -> DependencyGraph
Create a new empty dependency graph.
Sourcepub fn new(nodes: Vec<GraphNode>) -> DependencyGraph
pub fn new(nodes: Vec<GraphNode>) -> DependencyGraph
Create a new dependency graph from a list of nodes.
Sourcepub fn validate(&self) -> Result<(), Vec<ValidationError>>
pub fn validate(&self) -> Result<(), Vec<ValidationError>>
Validate the entire dependency graph.
Checks for:
- Circular dependencies (via DFS)
- Missing dependencies (references to types not in the graph)
- Duplicate node definitions
- Scope mismatches (wider-scope types depending on narrower-scope types)
Returns a list of validation errors. An empty list means the graph is valid.
Sourcepub fn topological_order(&self) -> Result<Vec<&str>, Vec<ValidationError>>
pub fn topological_order(&self) -> Result<Vec<&str>, Vec<ValidationError>>
Compute the topological order of the dependency graph.
Returns nodes in construction order (dependencies before dependents). Returns an error if the graph contains cycles.
Sourcepub fn destruction_order(&self) -> Result<Vec<&str>, Vec<ValidationError>>
pub fn destruction_order(&self) -> Result<Vec<&str>, Vec<ValidationError>>
Compute the destruction order (reverse topological).
Dependencies are destroyed after their dependents.
Trait Implementations§
Source§impl Clone for DependencyGraph
impl Clone for DependencyGraph
Source§fn clone(&self) -> DependencyGraph
fn clone(&self) -> DependencyGraph
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more