disintegrate_macros

Derive Macro Event

Source
#[derive(Event)]
{
    // Attributes available to this derive:
    #[stream]
    #[id]
}
Expand description

Derives the Event trait for an enum, allowing it to be used as an event in Disintegrate.

The Event trait is used to mark an enum as an event type in Disintegrate. By deriving this trait, the enum gains the necessary functionality to be used as an event.

The Event trait can be customized using attributes. The id attribute can be used to specify the domain identifier of an event, while the stream attribute can be used to stream related events together.

ยงExample

use disintegrate::Event;

#[derive(Event)]
#[stream(UserEvent, [UserRegistered, UserUpdated])]
#[stream(OrderEvent, [OrderCreated, OrderCancelled])]
enum DomainEvent{
    UserCreated {
        #[id]
        user_id: String,
        name: String,
        email: String,
    },
    UserUpdated {
        #[id]
        user_id: String,
        email: String,
    },
    OrderCreated {
        #[id]
        order_id: String,
        amount: u32
    },
    OrderCancelled {
        #[id]
        order_id: String
    },
}

In this example, the OrderEvent enum is marked as an event by deriving the Event trait. The #[stream] attribute specifies the event stream name and the list of variants to include in the stream, while the #[id] attribute is used to specify the domain identifiers of each variant.