Skip to main content

parse_connections

Macro parse_connections 

Source
macro_rules! parse_connections {
    ($builder:ident, graph . $input_name:ident : $value:expr => $node:ident . $port:ident $(, $rest:tt)*) => { ... };
    ($builder:ident, graph . $input_name:ident => $node:ident . $port:ident $(, $rest:tt)*) => { ... };
    ($builder:ident, $node:ident . $port:ident => graph . $output_name:ident $(, $rest:tt)*) => { ... };
    ($builder:ident, $source_node:ident . $source_port:ident => $target_node:ident . $target_port:ident $(, $rest:tt)*) => { ... };
    ($builder:ident, $(,)?) => { ... };
}
Expand description

Parses connection patterns and generates GraphBuilder method calls.

This macro is used internally by the graph! macro to parse connection syntax and generate the appropriate builder method calls.

§Supported Patterns

§Node-to-Node Connections

source_node.source_port => target_node.target_port

let mut builder = GraphBuilder::new("test");
builder = parse_connections!(builder, node1.out => node2.in);

§Graph Inputs

With value: graph.input_name: value => node.port

let mut builder = GraphBuilder::new("test");
builder = parse_connections!(builder, graph.config: 42i32 => node.in);

Without value: graph.input_name => node.port

let mut builder = GraphBuilder::new("test");
builder = parse_connections!(builder, graph.input => node.in);

§Graph Outputs

node.port => graph.output_name

let mut builder = GraphBuilder::new("test");
builder = parse_connections!(builder, node.out => graph.result);

§Multiple Connections

Multiple connections can be specified, separated by commas:

let mut builder = GraphBuilder::new("test");
builder = parse_connections!(
    builder,
    node1.out => node2.in,
    node2.out => node3.in,
    graph.input => node1.in,
    node3.out => graph.output
);

§Restrictions

  • Fan-out Not Supported: Same source port cannot connect to multiple targets
  • Fan-in Allowed: Multiple sources can connect to the same target port
  • Rule Ordering: Graph I/O patterns must be matched before node-to-node patterns (handled internally by macro rule ordering)

§Usage

This macro is typically used internally by graph!, but can be used directly for programmatic graph construction.