Skip to main content

SelfRouting

Derive Macro SelfRouting 

Source
#[derive(SelfRouting)]
Available on crate feature macros only.
Expand description

Derives Topic<Self> for Self enabling event-as-topic routing.

When an event type is used as its own topic, each variant becomes a distinct routing category. This is common in systems like Kafka where topic names match event types.

§Requirements

The type must also derive or implement:

  • Clone (for from_event to clone the event)
  • Hash, PartialEq, Eq (required by Topic trait)
  • Event (to be used in the actor system)

§Example

use maiko::{Event, SelfRouting};

#[derive(Clone, Debug, Hash, PartialEq, Eq, Event, SelfRouting)]
enum PingPongEvent {
    Ping,
    Pong,
}

// Now you can use PingPongEvent as both event and topic:
// Supervisor::<PingPongEvent, PingPongEvent>::default()