summaryrefslogtreecommitdiff
path: root/src/token/secret.rs
blob: 82a43b3a144c88ea112073730f41d63376ea9e05 (plain)
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
use std::fmt;

#[derive(PartialEq, Eq, sqlx::Type)]
#[sqlx(transparent)]
pub struct Secret(String);

impl Secret {
    pub fn reveal(self) -> String {
        let Self(secret) = self;
        secret
    }
}

impl fmt::Debug for Secret {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_tuple("Secret").field(&"********").finish()
    }
}

impl<S> From<S> for Secret
where
    S: Into<String>,
{
    fn from(value: S) -> Self {
        Self(value.into())
    }
}