use std::collections::HashMap; use std::future::Future; use actix_web::cookie::time::Duration; use crate::error::SessionError; use crate::key::SessionKey; pub type SessionState = HashMap; #[derive(Debug, Clone, Default, PartialEq, Eq)] pub struct SessionDiff { pub set: HashMap, pub removed: Vec, } impl SessionDiff { pub fn is_empty(&self) -> bool { self.set.is_empty() && self.removed.is_empty() } } pub trait SessionStore { fn load( &self, session_key: &SessionKey, ) -> impl Future, SessionError>>; fn save( &self, session_state: SessionState, ttl: &Duration, ) -> impl Future>; fn update( &self, session_key: SessionKey, diff: SessionDiff, ttl: &Duration, previous_user_id: Option, user_id: Option, ) -> impl Future>; fn rotate( &self, session_key: SessionKey, diff: SessionDiff, ttl: &Duration, previous_user_id: Option, user_id: Option, ) -> impl Future, SessionError>>; fn update_ttl( &self, session_key: &SessionKey, ttl: &Duration, user_id: Option, ) -> impl Future>; fn delete( &self, session_key: &SessionKey, user_id: Option, ) -> impl Future>; fn revoke_user(&self, user_id: i64) -> impl Future>; } pub fn generate_session_key() -> SessionKey { SessionKey::generate() }