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§
Sourcefn op_name(&self) -> &'static str
fn op_name(&self) -> &'static str
Stable identifier for the operation (e.g. "blur",
"scatter-dabs"). Matches the op field in the style JSON.
Sourcefn inputs(&self) -> &[PortSpec]
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.
Sourcefn output(&self, input_kinds: &[Option<PortKind>]) -> PortKind
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.
Sourcefn eval(
&self,
ctx: &EvalCtx<'_>,
inputs: &[Option<PortValue>],
) -> Result<PortValue, EvalError>
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.
Sourcefn param_hash(&self, hasher: &mut Xxh3)
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§
Sourcefn coord_space(&self) -> CoordSpace
fn coord_space(&self) -> CoordSpace
Coordinate space the node operates in. Defaults to inheriting from inputs.
Sourcefn required_pad(&self, downstream: u32) -> u32
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.
Sourcefn asset_inputs(&self) -> Vec<String>
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".