Skip to main content

Node

Trait Node 

Source
pub trait Node: Send + Sync {
    // Required methods
    fn op_name(&self) -> &'static str;
    fn inputs(&self) -> &[PortSpec];
    fn output(&self, input_kinds: &[Option<PortKind>]) -> PortKind;
    fn eval(
        &self,
        ctx: &EvalCtx<'_>,
        inputs: &[Option<PortValue>],
    ) -> Result<PortValue, EvalError>;
    fn param_hash(&self, hasher: &mut Xxh3);

    // Provided methods
    fn coord_space(&self) -> CoordSpace { ... }
    fn required_pad(&self, downstream: u32) -> u32 { ... }
    fn asset_inputs(&self) -> Vec<String> { ... }
}
Expand description

One operation in the DAG. Stored as Box<dyn Node> inside crate::Graph; the graph never mutates a node after construction.

Required Methods§

Source

fn op_name(&self) -> &'static str

Stable identifier for the operation (e.g. "blur", "scatter-dabs"). Matches the op field in the style JSON.

Source

fn inputs(&self) -> &[PortSpec]

Declared input ports in positional order. The style JSON connects each port by name; eval receives values in this same positional order.

Source

fn output(&self, input_kinds: &[Option<PortKind>]) -> PortKind

The kind of value this node produces.

input_kinds carries the resolved PortKind of each input port, in the same positional order as Node::inputs. Entries are Some for connected ports (including optional ones) and None for unconnected optional ports.

Most nodes return a constant; polymorphic nodes (e.g. blur accepting both Raster and Sprite) inspect input_kinds and mirror the upstream kind. The graph builder resolves nodes in topological order, so upstream kinds are always known when this is called.

Source

fn eval( &self, ctx: &EvalCtx<'_>, inputs: &[Option<PortValue>], ) -> Result<PortValue, EvalError>

Produce this node’s output given resolved inputs. inputs has one entry per declared port, in the order returned by Node::inputs; unconnected optional ports are None.

Source

fn param_hash(&self, hasher: &mut Xxh3)

Stable content hash of this node’s own parameters (not inputs). Used as part of the cache key. Implementations should feed every configuration value that influences output into the hasher.

Provided Methods§

Source

fn coord_space(&self) -> CoordSpace

Coordinate space the node operates in. Defaults to inheriting from inputs.

Source

fn required_pad(&self, downstream: u32) -> u32

How much canvas padding this node requires upstream given the padding requested by downstream consumers. Blur-like ops grow the value; most pass it through unchanged.

Source

fn asset_inputs(&self) -> Vec<String>

Named asset bindings this node samples via the AssetLoader. The evaluator folds each binding’s AssetLoader::hash into this node’s cache key, so changes in bound data invalidate caches automatically. Like declaring uniforms in a shader.

Default: no bindings.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§