anycms-event-derive 0.1.5

Procedural macros for anycms-event
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented0 out of 2 items with examples
  • Size
  • Source code size: 28.47 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 347.95 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 4s Average build duration of successful builds.
  • all releases: 4s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • anycms/anycms-event
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Liangdi

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