Skip to main content

Crate anycms_event_derive

Crate anycms_event_derive 

Source
Expand description

Procedural macros for the anycms-event crate.

Provides:

  • #[derive(Event)] — auto-implement the Event trait
  • event_bus! { ... } — define a typed event bus with compile-time guarantees

§#[derive(Event)]

Generates an impl Event for YourStruct block with event_name() and topic().

§Attributes

  • #[event(name = "user.created")] — set the event name explicitly
  • #[event(topic = "user")] — set the topic explicitly

If name is not specified, it is derived from the struct name using CamelCase convention: UserCreated -> "user.created", OrderPlaced -> "order.placed".

If topic is not specified, it defaults to the first segment of the event name (e.g., "user.created" -> "user").

§event_bus!

Define event structs, a topic enum, and a typed event bus in one declaration.

§Syntax

event_bus! {
    bus AppEventBus {
        event UserCreated { user_id: String, username: String }
        event UserDeleted { user_id: String, reason: String }

        // topic <method_name> => [EventType1, EventType2]
        topic user_events => [UserCreated, UserDeleted]
    }
}

This generates:

  • Struct definitions with #[derive(Debug, Clone, Serialize, Deserialize)]
  • impl Event for ... blocks
  • A topic enum AppEventBusTopicEvent
  • A typed AppEventBus newtype wrapping anycms_event::EventBus
  • A subscribe_topic_user_events() method for the topic group

Macros§

event_bus
Define a typed event bus with events and topic groupings.

Derive Macros§

Event
Derive macro for the Event trait.