use async_session::{serde::Serialize, Session};
use trillium::Conn;
pub trait SessionConnExt {
fn with_session(self, key: &str, value: impl Serialize) -> Self;
fn session(&self) -> &Session;
fn session_mut(&mut self) -> &mut Session;
}
impl SessionConnExt for Conn {
fn session(&self) -> &Session {
self.state()
.expect("SessionHandler must be executed before calling SessionConnExt::sessions")
}
fn with_session(mut self, key: &str, value: impl Serialize) -> Self {
self.session_mut().insert(key, value).ok();
self
}
fn session_mut(&mut self) -> &mut Session {
self.state_mut()
.expect("SessionHandler must be executed before calling SessionConnExt::sessions_mut")
}
}