pub(super) mod memory;
use std::future::Future;
use std::panic::RefUnwindSafe;
use std::pin::Pin;
use crate::middleware::session::{SessionError, SessionIdentifier};
use crate::state::State;
pub trait NewBackend: Sync + Clone + RefUnwindSafe {
type Instance: Backend + Send + 'static;
fn new_backend(&self) -> anyhow::Result<Self::Instance>;
}
pub type GetSessionFuture = dyn Future<Output = Result<Option<Vec<u8>>, SessionError>> + Send;
pub type SetSessionFuture = dyn Future<Output = Result<(), SessionError>> + Send;
pub trait Backend: Send {
fn persist_session(
&self,
state: &State,
identifier: SessionIdentifier,
content: &[u8],
) -> Pin<Box<SetSessionFuture>>;
fn read_session(
&self,
state: &State,
identifier: SessionIdentifier,
) -> Pin<Box<GetSessionFuture>>;
fn drop_session(
&self,
state: &State,
identifier: SessionIdentifier,
) -> Pin<Box<SetSessionFuture>>;
}