Skip to content

Latest commit

 

History

History
77 lines (56 loc) · 1.8 KB

File metadata and controls

77 lines (56 loc) · 1.8 KB

API Reference

Module trait

The core trait that all Neuron-Bridge modules must implement.

pub trait Module: Send + Sync {
    /// Unique identifier. Used as module_id in BridgeCommand::ExecuteCompute.
    fn id(&self) -> &'static str;

    /// Human-readable name for display.
    fn name(&self) -> &'static str;

    /// Execute compute logic.
    ///
    /// # Arguments
    /// * `payload` - Raw bytes from the client (module-specific format)
    ///
    /// # Returns
    /// * `Ok(Vec<u8>)` - Result bytes sent back to client
    /// * `Err(String)` - Error message sent as BridgeResponse::Error
    fn process(&self, payload: &[u8]) -> Result<Vec<u8>, String>;
}

Requirements

  • Send + Sync — modules are shared across async tasks via Arc
  • id() must return a unique, stable string
  • process() should validate input early and return descriptive errors

ModuleCreator

Factory function type for lazy module instantiation:

pub type ModuleCreator = fn() -> Box<dyn Module>;

load_all

Convenience function for bulk registration:

pub fn load_all(
    registry: &mut HashMap<&'static str, Box<dyn Module>>,
    providers: &[(&'static str, ModuleCreator)],
);

Registration Convention

Every module crate must expose two public symbols for the build system:

pub const MODULE_ID: &str = "my-module";
pub const NEURON_MODULE: ModuleCreator = || -> Box<dyn Module> { Box::new(MyModule) };

The server's build.rs scans module/ directories and generates code that references these symbols.

Cargo.toml

[package]
name = "my-module"
version = "0.1.0"
edition = "2024"

[lib]
crate-type = ["lib"]

[dependencies]
neuron-module-sdk = { git = "https://github.com/EAISD/neuron-module-sdk.git" }
ash = "0.37"  # Optional — for Vulkan GPU compute