Evento Macros
Procedural macros for the Evento event sourcing framework.
This crate provides macros that simplify building event-sourced applications by automatically generating boilerplate code for aggregators and event handlers.
More information about this crate can be found in the crate documentation.
Usage
This crate is typically used through the main evento crate with the macro feature enabled (which is on by default):
[]
= "1.5"
Or explicitly:
[]
= { = "1.5", = ["macro"] }
Provided Macros
#[evento::aggregator]
Automatically implements the Aggregator trait by generating event dispatching logic based on your handler methods.
use ;
use ;
use ;
The macro generates:
- Implementation of
evento::Aggregator::aggregatewith event dispatching - Implementation of
evento::Aggregator::revisionbased on a hash of handler methods - Implementation of
evento::AggregatorNameusing the package name and struct name
#[evento::handler(AggregateType)]
Creates an event handler for use with event subscriptions.
use ;
async
// Use with subscription
subscribe
.handler
.run
.await?;
The macro generates:
- A struct implementing
evento::SubscribeHandler - A constructor function returning an instance of that struct
- Type-safe event filtering based on the event type
#[derive(AggregatorName)]
Derives the AggregatorName trait which provides a name identifier for event types.
use AggregatorName;
use ;
assert_eq!;
Requirements
When using these macros, your types must implement the necessary traits:
- Aggregates must implement:
Default,Send,Sync,Clone,Debug,bincode::Encode,bincode::Decode - Events must implement:
bincode::Encode,bincode::Decode - Handler functions must be
asyncand returnanyhow::Result<()>
Minimum Supported Rust Version
Evento-macro's MSRV is 1.75.
Safety
This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% safe Rust.
Getting Help
If you have questions or need help, please:
- Check the documentation
- Look at the examples in the main evento repository
- Open an issue on GitHub
License
This project is licensed under the Apache-2.0 license.