@@ -39,8 +39,8 @@ pub enum MemoryStoreError {
3939impl SessionStore for MemoryStore {
4040 type Error = MemoryStoreError ;
4141
42- async fn load_session ( & self , cookie_value : String ) -> Result < Option < Session > , Self :: Error > {
43- let id = Session :: id_from_cookie_value ( & cookie_value) ?;
42+ async fn load_session ( & self , cookie_value : & str ) -> Result < Option < Session > , Self :: Error > {
43+ let id = Session :: id_from_cookie_value ( cookie_value) ?;
4444 log:: trace!( "loading session by id `{}`" , id) ;
4545 let Occupied ( entry) = self . 0 . entry ( id) else {
4646 return Ok ( None ) ;
@@ -54,14 +54,14 @@ impl SessionStore for MemoryStore {
5454 }
5555 }
5656
57- async fn store_session ( & self , mut session : Session ) -> Result < Option < String > , Self :: Error > {
57+ async fn store_session ( & self , session : & mut Session ) -> Result < Option < String > , Self :: Error > {
5858 log:: trace!( "storing session by id `{}`" , session. id( ) ) ;
5959 session. reset_data_changed ( ) ;
6060 self . 0 . insert ( session. id ( ) . to_string ( ) , session. clone ( ) ) ;
61- Ok ( session. into_cookie_value ( ) )
61+ Ok ( session. take_cookie_value ( ) )
6262 }
6363
64- async fn destroy_session ( & self , session : Session ) -> Result < ( ) , Self :: Error > {
64+ async fn destroy_session ( & self , session : & mut Session ) -> Result < ( ) , Self :: Error > {
6565 log:: trace!( "destroying session by id `{}`" , session. id( ) ) ;
6666 self . 0 . remove ( session. id ( ) ) ;
6767 Ok ( ( ) )
@@ -95,7 +95,7 @@ impl MemoryStore {
9595 /// # fn main() -> Result<(), Box<dyn std::error::Error>> { async_std::task::block_on(async {
9696 /// let mut store = MemoryStore::new();
9797 /// assert_eq!(store.count(), 0);
98- /// store.store_session(Session::new()).await?;
98+ /// store.store_session(&mut Session::new()).await?;
9999 /// assert_eq!(store.count(), 1);
100100 /// # Ok(()) }) }
101101 /// ```
@@ -115,7 +115,7 @@ mod tests {
115115 let mut session = Session :: new ( ) ;
116116 session. insert ( "key" , "Hello" ) ?;
117117 let cloned = session. clone ( ) ;
118- let cookie_value = store. store_session ( session) . await ?. unwrap ( ) ;
118+ let cookie_value = store. store_session ( & mut session) . await ?. unwrap ( ) ;
119119 let loaded_session = store. load_session ( cookie_value) . await ?. unwrap ( ) ;
120120 assert_eq ! ( cloned. id( ) , loaded_session. id( ) ) ;
121121 assert_eq ! ( "Hello" , & loaded_session. get:: <String >( "key" ) . unwrap( ) ) ;
@@ -130,14 +130,14 @@ mod tests {
130130 let mut session = Session :: new ( ) ;
131131
132132 session. insert ( "key" , "value" ) ?;
133- let cookie_value = store. store_session ( session) . await ?. unwrap ( ) ;
133+ let cookie_value = store. store_session ( & mut session) . await ?. unwrap ( ) ;
134134
135135 let mut session = store. load_session ( cookie_value. clone ( ) ) . await ?. unwrap ( ) ;
136136 session. insert ( "key" , "other value" ) ?;
137137
138- assert_eq ! ( store. store_session( session) . await ?, None ) ;
138+ assert_eq ! ( store. store_session( & mut session) . await ?, None ) ;
139139 let session = store. load_session ( cookie_value) . await ?. unwrap ( ) ;
140- assert_eq ! ( & session. get:: <String >( "key" ) . unwrap( ) , "other value" ) ;
140+ assert_eq ! ( & mut session. get:: <String >( "key" ) . unwrap( ) , "other value" ) ;
141141
142142 Ok ( ( ) )
143143 }
@@ -148,14 +148,14 @@ mod tests {
148148 let mut session = Session :: new ( ) ;
149149 session. expire_in ( Duration :: from_secs ( 1 ) ) ;
150150 let original_expires = * session. expiry ( ) . unwrap ( ) ;
151- let cookie_value = store. store_session ( session) . await ?. unwrap ( ) ;
151+ let cookie_value = store. store_session ( & mut session) . await ?. unwrap ( ) ;
152152
153153 let mut session = store. load_session ( cookie_value. clone ( ) ) . await ?. unwrap ( ) ;
154154
155155 assert_eq ! ( session. expiry( ) . unwrap( ) , & original_expires) ;
156156 session. expire_in ( Duration :: from_secs ( 3 ) ) ;
157157 let new_expires = * session. expiry ( ) . unwrap ( ) ;
158- assert_eq ! ( None , store. store_session( session) . await ?) ;
158+ assert_eq ! ( None , store. store_session( & mut session) . await ?) ;
159159
160160 let session = store. load_session ( cookie_value. clone ( ) ) . await ?. unwrap ( ) ;
161161 assert_eq ! ( session. expiry( ) . unwrap( ) , & new_expires) ;
@@ -174,7 +174,7 @@ mod tests {
174174 session. insert ( "key" , "value" ) ?;
175175 let cloned = session. clone ( ) ;
176176
177- let cookie_value = store. store_session ( session) . await ?. unwrap ( ) ;
177+ let cookie_value = store. store_session ( & mut session) . await ?. unwrap ( ) ;
178178
179179 let loaded_session = store. load_session ( cookie_value. clone ( ) ) . await ?. unwrap ( ) ;
180180 assert_eq ! ( cloned. id( ) , loaded_session. id( ) ) ;
@@ -192,26 +192,26 @@ mod tests {
192192 async fn destroying_a_single_session ( ) -> Result < ( ) , MemoryStoreError > {
193193 let store = MemoryStore :: new ( ) ;
194194 for _ in 0 ..3i8 {
195- store. store_session ( Session :: new ( ) ) . await ?;
195+ store. store_session ( & mut Session :: new ( ) ) . await ?;
196196 }
197197
198- let cookie = store. store_session ( Session :: new ( ) ) . await ?. unwrap ( ) ;
198+ let cookie = store. store_session ( & mut Session :: new ( ) ) . await ?. unwrap ( ) ;
199199 assert_eq ! ( 4 , store. count( ) ) ;
200- let session = store. load_session ( cookie. clone ( ) ) . await ?. unwrap ( ) ;
201- store. destroy_session ( session. clone ( ) ) . await ?;
200+ let mut session = store. load_session ( cookie. clone ( ) ) . await ?. unwrap ( ) ;
201+ store. destroy_session ( & mut session) . await ?;
202202 assert_eq ! ( None , store. load_session( cookie) . await ?) ;
203203 assert_eq ! ( 3 , store. count( ) ) ;
204204
205205 // attempting to destroy the session again is not an error
206- assert ! ( store. destroy_session( session) . await . is_ok( ) ) ;
206+ assert ! ( store. destroy_session( & mut session) . await . is_ok( ) ) ;
207207 Ok ( ( ) )
208208 }
209209
210210 #[ async_std:: test]
211211 async fn clearing_the_whole_store ( ) -> Result < ( ) , MemoryStoreError > {
212212 let store = MemoryStore :: new ( ) ;
213213 for _ in 0 ..3i8 {
214- store. store_session ( Session :: new ( ) ) . await ?;
214+ store. store_session ( & mut Session :: new ( ) ) . await ?;
215215 }
216216
217217 assert_eq ! ( 3 , store. count( ) ) ;
0 commit comments