trillium_sessions/
session_conn_ext.rs1use crate::SessionStoreError;
2use async_session::{Session, serde::Serialize};
3use trillium::Conn;
4
5pub trait SessionConnExt {
10 fn with_session(self, key: &str, value: impl Serialize) -> Self;
13
14 fn session(&self) -> &Session;
16
17 fn session_mut(&mut self) -> &mut Session;
19
20 fn session_store_error(&self) -> Option<&SessionStoreError>;
27}
28
29impl SessionConnExt for Conn {
30 fn session(&self) -> &Session {
31 self.state()
32 .expect("SessionHandler must be executed before calling SessionConnExt::sessions")
33 }
34
35 fn with_session(mut self, key: &str, value: impl Serialize) -> Self {
36 self.session_mut().insert(key, value).ok();
37 self
38 }
39
40 fn session_mut(&mut self) -> &mut Session {
41 self.state_mut()
42 .expect("SessionHandler must be executed before calling SessionConnExt::sessions_mut")
43 }
44
45 fn session_store_error(&self) -> Option<&SessionStoreError> {
46 self.state()
47 }
48}