Skip to main content

cyberdrop_client/
token.rs

1use std::fmt;
2
3use serde::Deserialize;
4
5/// Authentication token returned by [`crate::CyberdropClient::login`] and
6/// [`crate::CyberdropClient::register`].
7///
8/// This type is `#[serde(transparent)]` and typically deserializes from a JSON string.
9#[derive(Clone, PartialEq, Eq, Deserialize)]
10#[serde(transparent)]
11pub struct AuthToken {
12    pub(crate) token: String,
13}
14
15impl AuthToken {
16    /// Construct a new token wrapper.
17    pub fn new(token: impl Into<String>) -> Self {
18        Self {
19            token: token.into(),
20        }
21    }
22
23    /// Borrow the underlying token string.
24    pub fn as_str(&self) -> &str {
25        &self.token
26    }
27
28    /// Consume this value and return the underlying token string.
29    pub fn into_string(self) -> String {
30        self.token
31    }
32}
33
34impl fmt::Debug for AuthToken {
35    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36        f.debug_struct("AuthToken")
37            .field("token", &"<redacted>")
38            .finish()
39    }
40}