macro_rules! define_event {
(
$(#[$meta:meta])*
$vis:vis struct $name:ident {}
) => { ... };
(
$(#[$meta:meta])*
$vis:vis struct $name:ident {
$(
$(#[$field_meta:meta])*
$field_vis:vis $field:ident: $field_ty:ty
),* $(,)?
}
) => { ... };
}Expand description
Defines an event struct with cheap O(1) cloning using Arc
This macro generates:
- A hidden Inner struct containing all fields
- A public wrapper struct with Arc
- Clone implementation that clones the Arc (cheap)
- Constructor and accessor methods for all fields
- Event trait implementation
ยงExample
use reifydb_core::define_event;
define_event! {
pub struct MyEvent {
pub data: Vec<i32>,
pub name: String,
}
}
let event = MyEvent::new(vec![1, 2, 3], "test".to_string());
let clone = event.clone(); // O(1) operation, just increments Arc refcount
assert_eq!(event.data().len(), 3);
assert_eq!(event.name(), "test");