Skip to main content

AppEffectHandler

Trait AppEffectHandler 

Source
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§

Source

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::Error if the operation fails

Implementors§