Skip to main content

Module module

Module module 

Source
Expand description

Module trait and base implementations

This module provides the core Module trait which uses Generic Associated Types (GATs) for zero-cost async without boxing.

§GAT-based Design

Unlike async_trait which requires heap allocation, the GAT-based approach allows each implementation to specify its own future type, enabling:

  • Zero heap allocation for async execution
  • Compiler inlining across await points
  • Type-level Send bounds checking

§Example

struct MyModule;

impl Module for MyModule {
    type ForwardFut<'a> = impl Future<Output = Result<Prediction<'a>>> + Send + 'a;

    fn forward<'a>(&'a self, inputs: Inputs<'a>) -> Self::ForwardFut<'a> {
        async move {
            // Process inputs
            Ok(Prediction::new())
        }
    }
}

Structs§

BaseModule
Base module implementation with common functionality.
ChainedModule
Two modules chained sequentially.
FnModule
A module that wraps a function.
MappedModule
A module with mapped output.

Traits§

Module
Core trait for executable modules.
ModuleExt
Extension trait for Module providing additional combinators.