pub trait AppEffectHandler {
// Required method
fn execute(&mut self, effect: AppEffect) -> AppEffectResult;
}Expand description
Trait for executing app-level effects.
Implementors of this trait perform the actual I/O operations described
by AppEffect values. This separation enables:
- Testing: Mock handlers can record effects without performing I/O
- Batching: Handlers can optimize by batching similar operations
- Logging: Handlers can log all operations for debugging
§Example
ⓘ
struct MockHandler {
effects: Vec<AppEffect>,
}
impl AppEffectHandler for MockHandler {
fn execute(&mut self, effect: AppEffect) -> AppEffectResult {
self.effects.push(effect.clone());
AppEffectResult::Ok
}
}Required Methods§
Sourcefn execute(&mut self, effect: AppEffect) -> AppEffectResult
fn execute(&mut self, effect: AppEffect) -> AppEffectResult
Execute an effect and return the result.
Implementations should:
- Perform the actual I/O operation described by the effect
- Return the appropriate result variant
- Return
AppEffectResult::Errorif the operation fails