Skip to main content

HandlerInterface

Derive Macro HandlerInterface 

Source
#[derive(HandlerInterface)]
{
    // Attributes available to this derive:
    #[zestors]
}
Expand description

Derives the HandlerInterface trait for an enum, which dispatches each variant to the Handle<M> implementation of a Handler. Use it next to #[derive(Interface)] on the enum that is the handler’s Interface.

The generated code names rootcause::Report, so the crate using it must depend on rootcause.

§Example

use zestors::interface::{Envelope, Interface, Message};
use zestors::prelude::*;

#[derive(Message, Debug)]
struct Ping;

#[derive(Interface, HandlerInterface, Debug)]
enum PingInterface {
    Ping(Envelope<Ping>),
}

#[derive(Debug)]
struct Pinger;

impl Handler for Pinger {
    type Interface = PingInterface;
}

impl Handle<Ping> for Pinger {
    async fn handle(
        &mut self,
        _ctx: HandlerContext<'_, Self>,
        _msg: Ping,
        _req: (),
    ) -> Result<(), rootcause::Report> {
        Ok(())
    }
}