detsys_ids_client/
identity.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#[derive(serde::Deserialize, serde::Serialize, Clone, Debug, PartialEq, Eq)]
pub struct DistinctId(String);

impl From<String> for DistinctId {
    fn from(value: String) -> Self {
        Self(value)
    }
}

impl std::fmt::Display for DistinctId {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
        write!(f, "{}", self.0)
    }
}

#[derive(serde::Deserialize, serde::Serialize, Clone, Debug, PartialEq, Eq)]
pub struct DeviceId(String);

impl Default for DeviceId {
    fn default() -> Self {
        Self::new()
    }
}

impl DeviceId {
    pub fn new() -> DeviceId {
        DeviceId(format!("DIDS-DEV-{}", uuid::Uuid::now_v7()))
    }
}

impl std::fmt::Display for DeviceId {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
        write!(f, "{}", self.0)
    }
}

impl From<String> for DeviceId {
    fn from(value: String) -> Self {
        Self(value)
    }
}