#[derive(Graph)]
{
// Attributes available to this derive:
#[depends]
}
graphviz
only.Expand description
Automatically generate graph construction code from a Graphviz graph definition.
Note that the ordering of edge definitions is important. For any given
Dependencies
type, edges must be defined in the Graphviz specification in the order they appear in thestruct
.
Like futures in Rust, the type of a given graph is dependent on the code itself. Whilst two graphs can be thought of as ‘Resolving to a type T’, the actual type of the graph itself depends on exactly which nodes are constructed to produce that value.
This macro will also safely implement Send
for the graph definition.
Since Rc
types within the graph cannot be accessed, it is safe to
send the graph to another thread.
Usage
Provide a DAG definition in the Graphviz format. Each node must have a
label
attribute which corresponds to the name of the node type in
scope.
For nodes which have multiple dependencies, a class
attribute must be
provided which corresponds to the Dependencies
type.
#[derive(Graph)]
#[depends(
digraph Dag {
node_0 [label="NumberValue"];
node_1 [label="NumberValue"];
node_0 -> node_1 [label="Square"];
node_2 [label="NumberValue"];
node_3 [label="NumberValue"];
node_1 -> node_3 [label="Add", class="TwoNumbersDep"];
node_2 -> node_3 [label="Add", class="TwoNumbersDep"];
node_4 [label="NumberValue"];
node_3 -> node_4 [label="Square"];
}
)]
struct MyGraphBuilder;
// create a graph with some initial values.
let graph = MyGraphBuilder::create_dag(
NumberValue::new(7),
NumberValue::new(6),
NumberValue::default(),
NumberValue::default(),
NumberValue::default(),
);
// methods to update input nodes are generated.
graph.update_node_0(70).unwrap();
let mut visitor = HashSetVisitor::new();
graph.resolve(&mut visitor).unwrap();