pub trait EffectHandler<U = ()> {
type Request: FromCore;
// Required method
fn handle(
&mut self,
req: Self::Request,
cx: &EffectContext<'_, U>,
) -> Result<Value, EffectError>;
}Expand description
Handler for a single effect type.
Implement this trait for each Rust struct that handles one Haskell effect.
Request is the #[derive(FromCore)] enum mirroring the Haskell GADT.
ⓘ
impl EffectHandler for ConsoleHandler {
type Request = ConsoleReq;
fn handle(&mut self, req: ConsoleReq, cx: &EffectContext) -> Result<Value, EffectError> {
match req {
ConsoleReq::Print(msg) => { println!("{msg}"); cx.respond(()) }
}
}
}