axum_session_manager/
manager.rs

1use async_trait::async_trait;
2use std::fmt::Debug;
3
4/// Indicate User state  
5/// HaveSession's```T```contain user Data
6#[derive(Debug, Clone)]
7pub enum UserState<T> {
8    HaveSession(T),
9    NoSession,
10    NoCookie,
11}
12
13/// Wrapping UserState.
14/// Axum handler can get UserState by using ```Extention```
15#[derive(Debug, Clone)]
16pub struct UserData<T: Clone>(pub UserState<T>);
17
18/// Traits that implement session creation, confirmation, and deletion logic.  
19/// This trait enable SessionManagerService to verify session automatically using ```verify_session``` method.  
20#[async_trait]
21pub trait SessionManage<T>: Debug + Clone {
22    type SessionID: Clone + Send;
23    type UserInfo: Clone + Send;
24    type Error;
25
26    async fn add_session(&self, session_data: T) -> Result<Self::SessionID, Self::Error>;
27    async fn verify_session(&self, session_id: &str)
28        -> Result<Option<Self::UserInfo>, Self::Error>;
29    async fn delete_session(&self, session_id: &str) -> Result<(), Self::Error>;
30}