connect!() { /* proc-macro */ }Expand description
Avoid boilerplate when setting up the flowgraph.
connect! adds all mentioned blocks to the flowgraph if needed and then
records the requested connections. It leaves the local variable names bound
to typed block references, so they can be used later for inspection or
message calls.
let mut fg = Flowgraph::new();
connect!(fg,
src.out > shift.in;
shift > resamp1 > demod;
demod > resamp2 > snk;
);It roughly generates code like:
// Add all the blocks to the `Flowgraph`...
let src = fg.add(src);
let shift = fg.add(shift);
let resamp1 = fg.add(resamp1);
let demod = fg.add(demod);
let resamp2 = fg.add(resamp2);
let snk = fg.add(snk);
// ... and connect the ports appropriately
fg.stream(&src, |b| b.output(), &shift, |b| b.input())?;
fg.stream(&shift, |b| b.output(), &resamp1, |b| b.input())?;
fg.stream(&resamp1, |b| b.output(), &demod, |b| b.input())?;
fg.stream(&demod, |b| b.output(), &resamp2, |b| b.input())?;
fg.stream(&resamp2, |b| b.output(), &snk, |b| b.input())?;Connection endpoints are defined by block.port_name. Standard stream port
names can be omitted: a missing source port means output(), and a missing
destination port means input(). Message endpoints default to "out" and
"in".
Send-capable stream connections are indicated as >, while local-domain-only
stream connections for non-Send buffers are indicated as ~>. Message
connections are indicated as |.
Circuit-capable buffers are still connected with normal stream connections.
The < operator performs the additional circuit-closing step that sends
buffers back from the downstream end to the upstream start.
If a block uses non-standard port names it is possible to use triples, e.g.:
connect!(fg, src > input.foo.output > snk);Indexed stream ports generated from Vec<T> or [T; N] fields can be
selected with field[index]:
connect!(fg, src.output[0] > input.snk);It is possible to add blocks that have no connections by just putting them on a line separately.
connect!(fg, dummy);