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
use std::{ fmt::{self, Debug, Formatter}, sync::Arc, }; /// Represents a token. /// /// This is a wrapper around `Arc<String>` with the purpose of providing a safer /// API. In addition, its `Debug` implementation doesn't reveal the token. #[derive(PartialEq, Eq, Clone, Hash)] pub struct Token(Arc<String>); impl Token { /// Constructs a `Token`. pub fn new(token: String) -> Self { Self(Arc::new(token)) } pub(crate) fn as_str(&self) -> &str { self.0.as_str() } } impl Debug for Token { fn fmt(&self, formatter: &mut Formatter) -> fmt::Result { formatter.write_str("Token(..)") } }