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§
Source§impl<D, M> TryFrom<&Event> for EventData<D, M>where
D: Archive,
M: Archive,
<D as Archive>::Archived: for<'a> CheckBytes<Strategy<Validator<ArchiveValidator<'a>, SharedValidator>, Error>> + Deserialize<D, Strategy<Pool, Error>>,
<M as Archive>::Archived: for<'a> CheckBytes<Strategy<Validator<ArchiveValidator<'a>, SharedValidator>, Error>> + Deserialize<M, Strategy<Pool, Error>>,
impl<D, M> TryFrom<&Event> for EventData<D, M>where
D: Archive,
M: Archive,
<D as Archive>::Archived: for<'a> CheckBytes<Strategy<Validator<ArchiveValidator<'a>, SharedValidator>, Error>> + Deserialize<D, Strategy<Pool, Error>>,
<M as Archive>::Archived: for<'a> CheckBytes<Strategy<Validator<ArchiveValidator<'a>, SharedValidator>, Error>> + Deserialize<M, Strategy<Pool, Error>>,
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> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Returns the layout of the type.
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Returns whether the given value has been niched. Read more
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
Writes data to
out indicating that a T is niched.