server/domain/types/
user_id.rs1use serde::{Deserialize, Serialize};
2use uuid::Uuid;
3
4#[derive(Clone, Copy, Default, Debug, PartialEq, Eq, Serialize, Deserialize)]
6#[repr(transparent)]
7#[serde(transparent)]
8pub struct UserId(Uuid);
9
10impl UserId {
11 #[must_use]
13 #[inline]
14 pub fn new() -> Self {
15 Self::from(Uuid::new_v4())
16 }
17
18 #[inline]
20 #[must_use]
21 pub fn value(self) -> Uuid {
22 self.0
23 }
24}
25
26impl From<Uuid> for UserId {
27 fn from(value: Uuid) -> Self {
28 Self(value)
29 }
30}
31
32impl std::fmt::Display for UserId {
33 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34 write!(f, "UserId({})", self.0)
35 }
36}
37
38