pub trait Event: WriteXDR {
type Payload<'a>;
// Required methods
fn num_topics() -> u32
where Self: Sized;
fn signature() -> Option<&'static Topic>
where Self: Sized;
fn decode_payload<'a>(
bytes: &'a [u8],
) -> Result<Self::Payload<'a>, ReadError>;
// Provided method
fn topic<'a>(&'a self, index: u32) -> Option<TopicSrc<'a>> { ... }
}Expand description
Trait implemented by event types that can be emitted by contracts.
Provides the number of topics and their values. Topic 0 is conventionally the event-type discriminant (e.g. a hash of the event name). The XDR-serialized payload is everything after the topics in the on-chain representation.
Required Associated Types§
Required Methods§
Sourcefn num_topics() -> u32where
Self: Sized,
fn num_topics() -> u32where
Self: Sized,
Number of topics this event type carries (0..=3), including the signature topic when present.
This is a static property of the type: every emission carries the
same count, and typed-event matching (TypedEvent::try_new /
TypedEvent::new) rejects a raw event whose num_topics differs —
so a matching topic 0 plus a coincidentally decodable payload cannot
pass for an E emitted with a different topic count.
Sourcefn signature() -> Option<&'static Topic>where
Self: Sized,
fn signature() -> Option<&'static Topic>where
Self: Sized,
The static topic-0 discriminant for this event type, if it has one.
Topic 0 is conventionally the event-type discriminant (see the trait
docs). Return Some(sig) when topic 0 is a fixed per-type constant:
TypedEvent::new then rejects a raw event
whose topic 0 belongs to a different type before trusting the decoded
payload. Return None only when topic 0 is data-dependent (computed
from payload fields, or absent), which opts out of that check.
This is deliberately not defaulted: a silent None would let an impl
with a fixed discriminant skip the check by omission. #[derive(Event)]
implements it as Some(Self::SIGNATURE).
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".