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