pub struct Dag { /* private fields */ }Expand description
A directed acyclic graph of tasks.
Nodes are task ids; an edge dep -> task means task depends on dep
(so a topological sort yields dependencies before the tasks that need them).
Dependency nodes may be referenced before the dependency task itself is
added; Dag::validate catches any that are never registered.
Implementations§
Source§impl Dag
impl Dag
Sourcepub fn add_task(&mut self, task: Arc<dyn Task>) -> Result<()>
pub fn add_task(&mut self, task: Arc<dyn Task>) -> Result<()>
Register a task and wire up edges from its declared dependencies.
Returns an error on a duplicate id or a self-dependency. Missing
dependency tasks and cycles are reported later by Dag::validate.
Sourcepub fn dependencies_of(&self, id: &str) -> Vec<String>
pub fn dependencies_of(&self, id: &str) -> Vec<String>
Direct dependencies of id (incoming edges).
Sourcepub fn dependents_of(&self, id: &str) -> Vec<String>
pub fn dependents_of(&self, id: &str) -> Vec<String>
Direct dependents of id (outgoing edges).
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validate the graph: every dependency must be a registered task and the graph must be acyclic.
Sourcepub fn topological_order(&self) -> Result<Vec<String>>
pub fn topological_order(&self) -> Result<Vec<String>>
Return task ids in dependency order (dependencies first).
Errors if the graph contains a cycle.