#cqrs #event-sourcing #ddd #event-sourcing-cqrs

yanked eventcore-macros

Procedural macros for the EventCore event sourcing library

8 releases

0.1.8 Jul 23, 2025
0.1.7 Jul 22, 2025

#26 in #event-sourcing-cqrs

22 downloads per month
Used in union_square

MIT/Apache

15KB
217 lines

EventCore Macros

Procedural macros for the EventCore event sourcing library.

Overview

This crate provides derive macros and attribute macros to reduce boilerplate when implementing commands and other EventCore patterns.

Features

#[derive(Command)]

The Command derive macro helps implement the EventCore Command trait by:

  • Generating a type-safe StreamSet phantom type
  • Implementing the read_streams method based on #[stream] field attributes
  • Providing clear guidance on what methods still need manual implementation

Example

use eventcore_macros::Command;
use eventcore::types::StreamId;

#[derive(Command)]
struct TransferMoney {
    #[stream]
    from_account: StreamId,
    #[stream]
    to_account: StreamId,
    amount: Money,
}

// The macro generates:
// - TransferMoneyStreamSet phantom type
// - Implementation of read_streams() that returns [from_account, to_account]
//
// You still need to implement:
// - type Input = YourInputType
// - type State = YourStateType  
// - type Event = YourEventType
// - fn apply()
// - async fn handle()

Future Macros

Additional macros are planned for future releases:

  • command! declarative macro for simpler command definitions
  • #[stream] attribute enhancements
  • Helper macros for common patterns

License

Licensed under either of:

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~155–560KB
~13K SLoC