1use crate::{validation::validate_uuid_v4, Result};
2
3#[derive(Clone, Debug, PartialEq, Eq, Hash)]
5pub struct EventId(String);
6
7impl EventId {
8 pub fn new(id: impl Into<String>) -> Result<Self> {
10 validate_uuid_v4(id.into(), "Event ID").map(Self)
11 }
12
13 pub fn new_v4() -> Self {
15 Self(uuid::Uuid::new_v4().to_string())
16 }
17
18 pub fn as_str(&self) -> &str {
20 &self.0
21 }
22}
23
24impl std::fmt::Display for EventId {
25 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26 f.write_str(&self.0)
27 }
28}
29
30impl AsRef<str> for EventId {
31 fn as_ref(&self) -> &str {
32 &self.0
33 }
34}