use crate::{validation::validate_uuid_v4, Result};
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct EventId(String);
impl EventId {
pub fn new(id: impl Into<String>) -> Result<Self> {
validate_uuid_v4(id.into(), "Event ID").map(Self)
}
pub fn new_v4() -> Self {
Self(uuid::Uuid::new_v4().to_string())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl std::fmt::Display for EventId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.0)
}
}
impl AsRef<str> for EventId {
fn as_ref(&self) -> &str {
&self.0
}
}