Skip to main content

NodeFactory

Trait NodeFactory 

Source
pub trait NodeFactory: Send + Sync {
    // Required methods
    fn signatures(&self) -> &[FuncSig];
    fn build(
        &self,
        ctx: &BuildContext,
        name: &str,
        wires: &[WireRef],
        wire_types: &[PortType],
        consts: &[ConstArg],
    ) -> Result<Box<dyn PolydatNode>, String>;

    // Provided method
    fn validate(&self, _name: &str, _consts: &[ConstArg]) -> Result<(), String> { ... }
}
Expand description

What the registry builds a node through: a set of function signatures and the constructor for each.

Every node the compiler builds comes from a factory’s Self::build (crate::dsl::factory::build_node). A node module’s NodeRegistration, the form #[polydat_node] and register_nodes! emit, is a factory whose build is its registered NodeBuildFn. A host that wants a constructor of its own implements this trait and links the factory into the registry with a FactoryRegistration:

ⓘ
static COUNTERS: MyFactory = MyFactory::new();
polydat::inventory::submit! {
    polydat::dsl::registry::FactoryRegistration { factory: &COUNTERS }
}

Its nodes are then indistinguishable from built-in ones: same registry, same listings, same type checking, on every engine.

Required Methods§

Source

fn signatures(&self) -> &[FuncSig]

The functions this factory builds. The registry lists them, and a call to one of them is built by this factory.

Source

fn build( &self, ctx: &BuildContext, name: &str, wires: &[WireRef], wire_types: &[PortType], consts: &[ConstArg], ) -> Result<Box<dyn PolydatNode>, String>

Build the node name, one of Self::signatures, for the given wires, their resolved port types, and its constant arguments. ctx says which bindings are under construction and which resource scope the program tree has (BuildContext).

Provided Methods§

Source

fn validate(&self, _name: &str, _consts: &[ConstArg]) -> Result<(), String>

Check a call’s constant arguments before Self::build; an Err fails the compile as a bad constant, so build never sees a malformed literal. The registry has already applied each parameter’s declared ConstConstraint. Accepts everything unless overridden.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§