trillium_sessions/
session_conn_ext.rs1use async_session::{serde::Serialize, Session};
2use trillium::Conn;
3
4pub trait SessionConnExt {
11 fn with_session(self, key: &str, value: impl Serialize) -> Self;
16
17 fn session(&self) -> &Session;
21
22 fn session_mut(&mut self) -> &mut Session;
26}
27
28impl SessionConnExt for Conn {
29 fn session(&self) -> &Session {
30 self.state()
31 .expect("SessionHandler must be executed before calling SessionConnExt::sessions")
32 }
33
34 fn with_session(mut self, key: &str, value: impl Serialize) -> Self {
35 self.session_mut().insert(key, value).ok();
36 self
37 }
38
39 fn session_mut(&mut self) -> &mut Session {
40 self.state_mut()
41 .expect("SessionHandler must be executed before calling SessionConnExt::sessions_mut")
42 }
43}