use core::fmt::{Display, Formatter};
use crate::{Felt, utils::hash_string_to_word};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct EventId(Felt);
impl EventId {
pub fn from_name(name: impl AsRef<str>) -> Self {
let digest_word = hash_string_to_word(name.as_ref());
Self(digest_word[0])
}
pub const fn from_felt(value: Felt) -> Self {
Self(value)
}
pub const fn from_u64(value: u64) -> Self {
Self(Felt::new(value))
}
pub const fn as_felt(&self) -> Felt {
self.0
}
pub const fn is_reserved(&self) -> bool {
let value = self.0.as_int();
value <= u8::MAX as u64
}
}
impl PartialOrd for EventId {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for EventId {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
self.0.inner().cmp(&other.0.inner())
}
}
impl Display for EventId {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
core::fmt::Display::fmt(&self.0, f)
}
}