use std::sync::{Arc, RwLock};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SessionId(String);
impl SessionId {
pub fn new(id: String) -> Self {
Self(id)
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl AsRef<str> for SessionId {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for SessionId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone)]
pub struct ActiveSessionId(Arc<RwLock<String>>);
impl ActiveSessionId {
pub fn new(id: String) -> Self {
Self(Arc::new(RwLock::new(id)))
}
pub fn get(&self) -> String {
self.0.read().unwrap_or_else(|e| e.into_inner()).clone()
}
pub fn set(&self, id: String) {
*self.0.write().unwrap_or_else(|e| e.into_inner()) = id;
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SessionCookieName(String);
impl SessionCookieName {
pub fn new(name: String) -> Self {
Self(name)
}
pub fn as_str(&self) -> &str {
&self.0
}
}