server/domain/types/
game_id.rs1use serde::{Deserialize, Serialize};
2use uuid::Uuid;
3
4#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
8#[repr(transparent)]
9#[serde(transparent)]
10pub struct GameId(Uuid);
11
12impl GameId {
13 pub fn new() -> Self {
15 Self(Uuid::now_v7())
16 }
17
18 pub fn value(self) -> Uuid {
20 self.0
21 }
22}
23
24impl From<Uuid> for GameId {
25 fn from(value: Uuid) -> Self {
26 GameId(value)
27 }
28}
29
30impl std::str::FromStr for GameId {
31 type Err = uuid::Error;
32
33 fn from_str(s: &str) -> Result<Self, Self::Err> {
34 let uuid = Uuid::from_str(s)?;
35 Ok(GameId(uuid))
36 }
37}
38
39impl std::fmt::Display for GameId {
40 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41 write!(f, "GameId({})", self.0)
42 }
43}
44
45