macro_rules! graph { ( with_node: $node:expr, with_edges: $type:tt, nodes: [$($ident:expr),*], connections: [ $($from:expr => {$(($cost:expr) $to:expr),+}),* ] ) => { ... }; ( with_edges: $type:tt, nodes: [$($ident:expr => $node:expr),*], connections: [ $($from:expr => {$(($cost:expr) $to:expr),+}),* ] ) => { ... }; ( nodes: [$($ident:expr => $node:expr),*], connections: [ $($from:expr => {$(($type:tt, $cost:expr) {$($to:expr),+}),+}),* ] ) => { ... }; }
Expand description
Declarative way to create Graph instances with ease.
The macro has two main fields:
nodes
: A list of node identifiers (names)connections
: A list of typeidentifier => connections
There is the possibility to create overloading equivalent macros to initialize
sets of fields to the same value. E.g. the with_edges
field makes all edges to be of
a specific type.
Example:
use graph::{Graph, graph, count};
let graph: Graph<&str, (), u8, graph::Directed, u32> = graph! {
with_node: (),
with_edges: unchecked_next,
nodes: [ "A", "B", "C", "D", "E" ],
connections: [
"A" => { (7) "C", (10) "B" },
"B" => { (4) "C", (11) "D" },
"D" => { (5) "E" }
]
};