pub struct EventId(/* private fields */);
Expand description
A type-safe wrapper around a Felt
that represents an event identifier.
Event IDs are used to identify events that can be emitted by the VM or handled by the host.
This newtype provides type safety and ensures that event IDs are not accidentally confused
with other Felt
values.
While not enforced by this type, the values 0..256 are reserved for
SystemEvent
s.
Implementations§
Source§impl EventId
impl EventId
Sourcepub fn from_name(name: impl AsRef<str>) -> Self
pub fn from_name(name: impl AsRef<str>) -> Self
Computes the canonical event identifier for the given name
.
This function provides a stable, deterministic mapping from human-readable event names to field elements that can be used as event identifiers in the VM. The mapping works by:
- Computing the BLAKE3 hash of the event name (produces 32 bytes)
- Taking the first 8 bytes of the hash
- Interpreting these bytes as a little-endian u64
- Reducing modulo the field prime to create a valid Felt
Note that this is the same procedure performed by hash_string_to_word
, where we take
the first element of the resulting Word
.
This ensures that identical event names always produce the same event ID, while providing good distribution properties to minimize collisions between different names.
Sourcepub const fn from_u64(value: u64) -> Self
pub const fn from_u64(value: u64) -> Self
Creates a new event ID from a u64, converting it to a Felt
.
Sourcepub const fn is_reserved(&self) -> bool
pub const fn is_reserved(&self) -> bool
Returns true
if this event ID is reserved for a
SystemEvent
.