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.
EventId contains only the identifier. For events with human-readable names,
use EventName instead.
Event IDs are derived from event names using blake3 hashing.
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_felt(event_id: Felt) -> Self
pub const fn from_felt(event_id: Felt) -> Self
Creates an EventId from a Felt value (e.g., from the stack).
Trait Implementations§
Source§impl Deserializable for EventId
impl Deserializable for EventId
Source§fn read_from<R: ByteReader>(
source: &mut R,
) -> Result<Self, DeserializationError>
fn read_from<R: ByteReader>( source: &mut R, ) -> Result<Self, DeserializationError>
source, attempts to deserialize these bytes
into Self, and returns the result. Read moreSource§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
Source§impl Ord for EventId
impl Ord for EventId
Source§impl PartialOrd for EventId
impl PartialOrd for EventId
Source§impl Serializable for EventId
impl Serializable for EventId
Source§fn write_into<W: ByteWriter>(&self, target: &mut W)
fn write_into<W: ByteWriter>(&self, target: &mut W)
self into bytes and writes these bytes into the target.