use async_trait::async_trait;
use super::session::Session;
#[derive(Debug)]
pub enum SessionError {
NotFound(String),
StoreError(String),
}
impl std::fmt::Display for SessionError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SessionError::NotFound(id) => write!(f, "Session 不存在: {}", id),
SessionError::StoreError(msg) => write!(f, "Session 存储错误: {}", msg),
}
}
}
impl std::error::Error for SessionError {}
#[async_trait]
pub trait SessionStore: Send + Sync {
async fn create(&self, session: Session) -> Result<String, SessionError>;
async fn get(&self, id: &str) -> Result<Option<Session>, SessionError>;
async fn update(&self, session: &Session) -> Result<(), SessionError>;
async fn delete(&self, id: &str) -> Result<(), SessionError>;
async fn list_by_user(&self, user_id: &str) -> Result<Vec<Session>, SessionError>;
}