macro_rules! link {
(
//. .
($pcname: ident = $pcval: expr),
//. .
($($input_name: ident = $input_val: expr), * $(,) ?),
//. .
($($output_name: ident = $output_val: expr), * $(,) ?),
//. .
($($name: ident = $val: expr), * $(,) ?) $(,) ?
//. .
$body: block) => { ... };
}
Expand description
Define a link, a callback that triggers during event graph processing if any of the inputs change. A link will also be triggered during the event the link was created in, whether inputs changed or not.
Link specification is like defining a closure, however all captures must be explicitly defined up front. The macro takes the form of a function definition with multiple parentheses for different capture groups.
let _link = link!(
(CONTEXT KVS),
(INPUT KVS),
(OUTPUT KVS),
(OTHER CAPTURE KVS) {
BODY
});
-
Each
KVS
group takes values in the form ofx1 = x2
wherex2
is an expression for a value that will be used inside the link callback, andx1
is the name it’s assigned within the callback. -
CONTEXT KVS
looks likepc = pc
, it takes theProcessingContext
from the current event. -
INPUT KVS
is a list of input values which will trigger this callback to run. This needs at least one item. -
OUTPUT KVS
is a list of values that may be modified by this callback. This can be empty if the callback doesn’t cause any downstream processing - for example, in a UI a callback that updates view state. -
OTHER CAPTURE KVS
is a list of other values to capture not related to graph processing. This can be empty. -
BODY
is the code of the callback. It should read from the inputs and modify the outputs. It implicitly (no explicit return needed) returns anOption<()>
to help with short circuiting, for example if you use a weak reference to an input and upgrading that input results in None.
The link returns a link object. The link callback will only trigger as long as that object exists, so you need to own it as long as it’s relevant.