#[cfg(all(feature = "db", feature = "json"))]
pub mod db;
#[cfg(feature = "json")]
pub mod file;
pub mod memory;
#[cfg(feature = "redis")]
pub mod redis;
use std::sync::Arc;
use async_trait::async_trait;
use tower_sessions::session::{Id, Record};
use tower_sessions::{SessionStore, session_store};
pub(crate) const MAX_COLLISION_RETRIES: u32 = 32;
pub(crate) const ERROR_PREFIX: &str = "session store:";
#[derive(Debug, Clone)]
pub struct SessionStoreWrapper(Arc<dyn SessionStore>);
impl SessionStoreWrapper {
pub fn new(boxed: Arc<dyn SessionStore + Send + Sync>) -> Self {
Self(boxed)
}
}
#[async_trait]
impl SessionStore for SessionStoreWrapper {
async fn save(&self, session_record: &Record) -> session_store::Result<()> {
self.0.save(session_record).await
}
async fn load(&self, session_id: &Id) -> session_store::Result<Option<Record>> {
self.0.load(session_id).await
}
async fn delete(&self, session_id: &Id) -> session_store::Result<()> {
self.0.delete(session_id).await
}
}