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§
- Base
Module - Base module implementation with common functionality.
- Chained
Module - Two modules chained sequentially.
- FnModule
- A module that wraps a function.
- Mapped
Module - A module with mapped output.