pub trait Node: Any {
Show 13 methods
// Required method
fn expr(&self, ctx: ExprCtx<'_, '_>) -> ExprResult;
// Provided methods
fn n_inputs(&self, _ctx: MetaCtx<'_>) -> usize { ... }
fn n_outputs(&self, _ctx: MetaCtx<'_>) -> usize { ... }
fn branches(&self, _ctx: MetaCtx<'_>) -> Vec<EvalConf> { ... }
fn push_eval(&self, _ctx: MetaCtx<'_>) -> Vec<EvalConf> { ... }
fn pull_eval(&self, _ctx: MetaCtx<'_>) -> Vec<EvalConf> { ... }
fn inlet(&self, _ctx: MetaCtx<'_>) -> bool { ... }
fn outlet(&self, _ctx: MetaCtx<'_>) -> bool { ... }
fn delay(&self, _ctx: MetaCtx<'_>) -> bool { ... }
fn stateful(&self, _ctx: MetaCtx<'_>) -> bool { ... }
fn register(&self, _ctx: RegCtx<'_, '_>) { ... }
fn required_addrs(&self) -> Vec<ContentAddr> { ... }
fn visit(&self, _ctx: Ctx<'_, '_>, _visitor: &mut dyn Visitor) { ... }
}Expand description
The definitive abstraction of a gantz graph, the gantz Node trait.
The std::any::Any supertrait enables Visitor implementations to
downcast &dyn Node to concrete types via visit::TypedVisitor.
Required Methods§
Sourcefn expr(&self, ctx: ExprCtx<'_, '_>) -> ExprResult
fn expr(&self, ctx: ExprCtx<'_, '_>) -> ExprResult
The expression that, given the expressions of connected inputs, produces the output(s).
The given inputs slice is guaranteed to match the length of a call to
Node::n_inputs immediately prior. Inputs are Some in the case that
they are connected, and None otherwise.
At runtime, each connected input binding holds a single value when
exactly one edge targets that input index. When multiple unconditional
edges target the same input index, the binding holds a (list ...) of
all incoming values in topological source order.
If Node::n_outputs is 1, the expr should result in a single value.
If Node::n_outputs is > 1, the expr should result in a list of values.
Provided Methods§
Sourcefn n_inputs(&self, _ctx: MetaCtx<'_>) -> usize
fn n_inputs(&self, _ctx: MetaCtx<'_>) -> usize
The number of inputs to the node.
The maximum number is Conns::MAX.
Sourcefn n_outputs(&self, _ctx: MetaCtx<'_>) -> usize
fn n_outputs(&self, _ctx: MetaCtx<'_>) -> usize
The number of outputs from the node.
The maximum number is Conns::MAX.
Sourcefn branches(&self, _ctx: MetaCtx<'_>) -> Vec<EvalConf>
fn branches(&self, _ctx: MetaCtx<'_>) -> Vec<EvalConf>
The list of possible branches from this node.
Each branch is represented as a set of outputs that are enabled for that branch.
This is intended for nodes that conditionally activate outputs based on some received input.
If the returned Vec is empty, we assume the node has no branching, and
simply evaluates to all outputs.
If the returned Vec is non-empty, the expression returned from
Node::expr method must return a list with two elements where the
first element is the index of the selected branch, and the second
element is the node’s output value(s).
By default, this is vec![].
Sourcefn push_eval(&self, _ctx: MetaCtx<'_>) -> Vec<EvalConf>
fn push_eval(&self, _ctx: MetaCtx<'_>) -> Vec<EvalConf>
Specifies whether or not code should be generated to allow for push evaluation from instances of this node. Enabling push evaluation allows applications to call into the graph by calling the resulting generated code at runtime.
Push evaluation order is equivalent to a topological ordering of the
connected component that starts from the push_eval node.
Within a Graph node, a new function will be generated for each
EvalConf set for each node. If Some, a function will be generated
with the given Signature that represents pushing evaluation from
this node.
By default, this is an empty vec.
Sourcefn pull_eval(&self, _ctx: MetaCtx<'_>) -> Vec<EvalConf>
fn pull_eval(&self, _ctx: MetaCtx<'_>) -> Vec<EvalConf>
Specifies whether or not code should be generated to allow for pull evaluation from instances of this node. Enabling pull evaluation allows applications to call into the graph by loading the resulting generated code at runtime.
Pull evaluation order is equivalent to a topological ordering of the
connected component that ends at the pull_eval node.
Within a Graph node, a new function will be generated for each node that signals Some. If Some, a function will be generated with the given Signature that represents pulling evaluation from this node.
By default, this is an empty vec.
Sourcefn inlet(&self, _ctx: MetaCtx<'_>) -> bool
fn inlet(&self, _ctx: MetaCtx<'_>) -> bool
Whether or not this node acts as an inlet for some nested graph.
Sourcefn outlet(&self, _ctx: MetaCtx<'_>) -> bool
fn outlet(&self, _ctx: MetaCtx<'_>) -> bool
Whether or not this node acts as an outlet for some nested graph.
Sourcefn delay(&self, _ctx: MetaCtx<'_>) -> bool
fn delay(&self, _ctx: MetaCtx<'_>) -> bool
Whether or not this node is a unit delay: its output is the value its input received on the previous evaluation.
Delay nodes are compiler intrinsics (no Node::expr is generated):
their value is read from state when an evaluation begins, and their
input is stored to state where it is produced. Evaluation never
propagates through a delay, so a cycle containing one is legal -
this is the pd-style feedback primitive.
Sourcefn stateful(&self, _ctx: MetaCtx<'_>) -> bool
fn stateful(&self, _ctx: MetaCtx<'_>) -> bool
Whether or not the node requires access to state.
Nodes returning true will have a special state variable accessible
within their Node::expr provided during compilation.
Sourcefn register(&self, _ctx: RegCtx<'_, '_>)
fn register(&self, _ctx: RegCtx<'_, '_>)
Function for registering necessary types, functions and initialising any default values as necessary.
This method is called each time the graph changes and must be idempotent.
Implementations should check whether state already exists before
initializing to avoid resetting existing state. See
state::init_value_if_absent and state::init_if_absent.
Nodes returning true from their Node::stateful implementation
must use this to initialise their state.
By default, the node is assumed to be stateless, and this does nothing.
Sourcefn required_addrs(&self) -> Vec<ContentAddr>
fn required_addrs(&self) -> Vec<ContentAddr>
Returns the content addresses of external nodes this node requires.
Used during pruning to determine which commits/graphs are still in use.
Nodes that reference other graphs (like Ref, NamedRef) should return
the addresses they depend on.
By default, returns an empty vec (no external dependencies).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".