Skip to main content

Node

Trait Node 

Source
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§

Source

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§

Source

fn n_inputs(&self, _ctx: MetaCtx<'_>) -> usize

The number of inputs to the node.

The maximum number is Conns::MAX.

Source

fn n_outputs(&self, _ctx: MetaCtx<'_>) -> usize

The number of outputs from the node.

The maximum number is Conns::MAX.

Source

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![].

Source

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.

Source

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.

Source

fn inlet(&self, _ctx: MetaCtx<'_>) -> bool

Whether or not this node acts as an inlet for some nested graph.

Source

fn outlet(&self, _ctx: MetaCtx<'_>) -> bool

Whether or not this node acts as an outlet for some nested graph.

Source

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.

Source

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.

Source

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.

Source

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).

Source

fn visit(&self, _ctx: Ctx<'_, '_>, _visitor: &mut dyn Visitor)

Traverse all nested nodes, depth-first, with the given Visitor.

For each nested node:

  1. Visitor::visit_pre
  2. Node::visit
  3. Visitor::visit_post

Note that implementations should only visit nested nodes and not the node itself. To visit the node and all nested nodes, use the visit() function.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T> Node for Arc<T>
where T: ?Sized + Node,

Source§

fn n_inputs(&self, ctx: MetaCtx<'_>) -> usize

Source§

fn n_outputs(&self, ctx: MetaCtx<'_>) -> usize

Source§

fn branches(&self, ctx: MetaCtx<'_>) -> Vec<EvalConf>

Source§

fn expr(&self, ctx: ExprCtx<'_, '_>) -> ExprResult

Source§

fn push_eval(&self, ctx: MetaCtx<'_>) -> Vec<EvalConf>

Source§

fn pull_eval(&self, ctx: MetaCtx<'_>) -> Vec<EvalConf>

Source§

fn inlet(&self, ctx: MetaCtx<'_>) -> bool

Source§

fn outlet(&self, ctx: MetaCtx<'_>) -> bool

Source§

fn delay(&self, ctx: MetaCtx<'_>) -> bool

Source§

fn stateful(&self, ctx: MetaCtx<'_>) -> bool

Source§

fn register(&self, ctx: RegCtx<'_, '_>)

Source§

fn required_addrs(&self) -> Vec<ContentAddr>

Source§

fn visit(&self, ctx: Ctx<'_, '_>, visitor: &mut dyn Visitor)

Source§

impl<T> Node for Box<T>
where T: ?Sized + Node,

Source§

fn n_inputs(&self, ctx: MetaCtx<'_>) -> usize

Source§

fn n_outputs(&self, ctx: MetaCtx<'_>) -> usize

Source§

fn branches(&self, ctx: MetaCtx<'_>) -> Vec<EvalConf>

Source§

fn expr(&self, ctx: ExprCtx<'_, '_>) -> ExprResult

Source§

fn push_eval(&self, ctx: MetaCtx<'_>) -> Vec<EvalConf>

Source§

fn pull_eval(&self, ctx: MetaCtx<'_>) -> Vec<EvalConf>

Source§

fn inlet(&self, ctx: MetaCtx<'_>) -> bool

Source§

fn outlet(&self, ctx: MetaCtx<'_>) -> bool

Source§

fn delay(&self, ctx: MetaCtx<'_>) -> bool

Source§

fn stateful(&self, ctx: MetaCtx<'_>) -> bool

Source§

fn register(&self, ctx: RegCtx<'_, '_>)

Source§

fn required_addrs(&self) -> Vec<ContentAddr>

Source§

fn visit(&self, ctx: Ctx<'_, '_>, visitor: &mut dyn Visitor)

Source§

impl<T> Node for Rc<T>
where T: ?Sized + Node,

Source§

fn n_inputs(&self, ctx: MetaCtx<'_>) -> usize

Source§

fn n_outputs(&self, ctx: MetaCtx<'_>) -> usize

Source§

fn branches(&self, ctx: MetaCtx<'_>) -> Vec<EvalConf>

Source§

fn expr(&self, ctx: ExprCtx<'_, '_>) -> ExprResult

Source§

fn push_eval(&self, ctx: MetaCtx<'_>) -> Vec<EvalConf>

Source§

fn pull_eval(&self, ctx: MetaCtx<'_>) -> Vec<EvalConf>

Source§

fn inlet(&self, ctx: MetaCtx<'_>) -> bool

Source§

fn outlet(&self, ctx: MetaCtx<'_>) -> bool

Source§

fn delay(&self, ctx: MetaCtx<'_>) -> bool

Source§

fn stateful(&self, ctx: MetaCtx<'_>) -> bool

Source§

fn register(&self, ctx: RegCtx<'_, '_>)

Source§

fn required_addrs(&self) -> Vec<ContentAddr>

Source§

fn visit(&self, ctx: Ctx<'_, '_>, visitor: &mut dyn Visitor)

Implementors§

Source§

impl Node for Apply

Source§

impl Node for Branch

Source§

impl Node for Delay

Source§

impl Node for Expr

Source§

impl Node for Identity

Source§

impl Node for Inlet

Source§

impl Node for Outlet

Source§

impl Node for Ref

Source§

impl<N, S> Node for State<N, S>
where N: Node, S: NodeState + 'static,

Source§

impl<N: Node> Node for Fn<N>

Source§

impl<N: Node> Node for Graph<N>

Source§

impl<N: Node> Node for Pull<N>

Source§

impl<N: Node> Node for Push<N>