Parser

More convenient ways to define nodes and build the graph.

Auto implementation for Node trait

Implementing the Node trait for tons of custom types is a bit of a waste of time. for example you need to implement the id method for all of them, which just return a NodeId but you have to write such code over and over again.

Dagrs provides the procedural macro auto_node to simplify implementing the Node trait for custom types. As the following example goes, macro auto_node will add neccery fields to your custom type, and implement the Node trait for this type.

use dagrs::{auto_node}

#[auto_node]
struct MyNode {/*Put customized fields here.*/}

#[auto_node]
struct MyNodeGeneric<T, 'a> {
    my_field: Vec<T>,
    my_name: &'a str,
}

#[auto_node]
struct MyUnitNode;

Note:

The macro auto_node currently doen't work on tuple structs.

Auto implementation for build the graph

Dagrs also provides an easy way to build a graph using the dependencies! macro. This eliminates the need to manually add nodes and edges one by one, saving time and making the process more straightforward. The macro allows you to define node dependencies directly in a concise and readable format.

Here’s an example demonstrating how to use the dependencies! macro to construct a graph:

use dagrs::dependencies;
let s = MyNode::new(node_name, &mut node_table);
let a = MyNode::new(node_name, &mut node_table);
let b = MyNode::new(node_name, &mut node_table);
let mut g = dependencies!(
        s -> a b,
        b -> a
);

The nodes s, a, and b are created using the MyNode type, which automatically implements the Node trait via the auto_node macro. The dependencies! macro defines the relationships between nodes in a concise format, where s -> a b indicates that there is a channel from s to a and b, and b -> a specifies a channel from b to a. This macro simplifies graph construction by automatically generating the required structure with all specified nodes and their dependencies, avoiding repetitive and boilerplate code.

The g variable represents the generated graph, which is automatically constructed by the dependencies! macro based on the defined node relationships.