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
42
43
44
45
46
47
48
use std::ops::Deref;

use serde::{Deserialize, Serialize};
use zbus::zvariant::Type;

/// A token that can be used to activate an application.
///
/// No guarantees are made for the token structure.
#[derive(Debug, Deserialize, Serialize, Type, PartialEq, Eq, Hash, Clone)]
pub struct ActivationToken(String);

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

impl From<&str> for ActivationToken {
    fn from(value: &str) -> Self {
        Self(value.to_owned())
    }
}

impl From<ActivationToken> for String {
    fn from(value: ActivationToken) -> String {
        value.0
    }
}

impl Deref for ActivationToken {
    type Target = str;

    fn deref(&self) -> &Self::Target {
        self.0.as_str()
    }
}

impl AsRef<str> for ActivationToken {
    fn as_ref(&self) -> &str {
        self.0.as_str()
    }
}

impl std::fmt::Display for ActivationToken {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_ref())
    }
}