appletheia_application/request_context/
causation_id.rs1use std::{fmt, fmt::Display};
2
3use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6use crate::request_context::MessageId;
7use appletheia_domain::event::EventId;
8
9#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd, Serialize, Deserialize)]
10#[serde(transparent)]
11pub struct CausationId(Uuid);
12
13impl CausationId {
14 pub fn value(&self) -> Uuid {
15 self.0
16 }
17}
18
19impl From<MessageId> for CausationId {
20 fn from(value: MessageId) -> Self {
21 Self(value.value())
22 }
23}
24
25impl From<EventId> for CausationId {
26 fn from(value: EventId) -> Self {
27 Self(value.value())
28 }
29}
30
31impl From<CausationId> for Uuid {
32 fn from(value: CausationId) -> Self {
33 value.0
34 }
35}
36
37impl Display for CausationId {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 write!(f, "{}", self.0)
40 }
41}