Skip to main content

Module

Trait Module 

Source
pub trait Module {
    // Required methods
    fn name(&self) -> &str;
    fn body(&self, g: &mut Graph);

    // Provided methods
    fn bootstrap(&self, _g: &mut Graph) { ... }
    fn op(
        &self,
        g: &mut Graph,
        bindings: &[(String, Output)],
    ) -> Vec<(String, String)> { ... }
    fn call(&self) -> ModuleCall<'_, Self> { ... }
    fn build(self) -> Result<ModelProto, BuildError>
       where Self: Sized { ... }
}
Expand description

Unit of composition. Implement name() + body(); framework supplies op() and build(). Body declares inputs via g.input("name") and emits via g.output("name", value) (local) or g.net_out("name", peers, value) (network).

Required Methods§

Source

fn name(&self) -> &str

Short stable identifier — becomes FunctionProto.name.

Source

fn body(&self, g: &mut Graph)

Recording logic. Compose child Modules via self.child.call().input(...).build(g).output(...).

Provided Methods§

Source

fn bootstrap(&self, _g: &mut Graph)

Setup recording, run once before the first body poll. May emit ContractResponse::Later; the engine drains every outstanding bootstrap completion before activating body ops.

Source

fn op( &self, g: &mut Graph, bindings: &[(String, Output)], ) -> Vec<(String, String)>

Records body() into a function scope named self.name(). Emits a CALL in the outer target. Do not override.

Source

fn call(&self) -> ModuleCall<'_, Self>

Open a fluent call-site that inlines self’s body.

Source

fn build(self) -> Result<ModelProto, BuildError>
where Self: Sized,

Emit one pre-compile ModelProto. Body becomes functions[0] stamped with module_phase = "body". If bootstrap recorded any ops it lands as a sibling "<name>__bootstrap" stamped with "bootstrap".

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§