pub struct EventData<D, M = bool> {
pub data: D,
pub metadata: M,
/* private fields */
}Expand description
Typed event with deserialized data and metadata.
EventData wraps a raw Event and provides typed access
to the deserialized event data and metadata. It implements Deref to
provide access to the underlying event fields (id, timestamp, version, etc.).
§Type Parameters
D: The event data type (e.g.,AccountOpened)M: The metadata type (defaults toboolfor no metadata)
§Example
ⓘ
use evento::metadata::Event;
#[evento::handler]
async fn handle_deposit<E: Executor>(
event: Event<MoneyDeposited>,
action: Action<'_, AccountView, E>,
) -> anyhow::Result<()> {
// Access typed data
println!("Amount: {}", event.data.amount);
// Access metadata
if let Ok(user) = event.metadata.user() {
println!("By user: {}", user);
}
// Access underlying event fields via Deref
println!("Event ID: {}", event.id);
println!("Version: {}", event.version);
Ok(())
}Fields§
§data: DThe typed event data
metadata: MThe typed event metadata
Trait Implementations§
Auto Trait Implementations§
impl<D, M> Freeze for EventData<D, M>
impl<D, M> RefUnwindSafe for EventData<D, M>where
D: RefUnwindSafe,
M: RefUnwindSafe,
impl<D, M> Send for EventData<D, M>
impl<D, M> Sync for EventData<D, M>
impl<D, M> Unpin for EventData<D, M>
impl<D, M> UnwindSafe for EventData<D, M>where
D: UnwindSafe,
M: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more