@@ -57,8 +57,9 @@ impl SessionStore for MemoryStore {
5757 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 ( ) ;
60+ let cookie_value = session. take_cookie_value ( ) ;
6061 self . 0 . insert ( session. id ( ) . to_string ( ) , session. clone ( ) ) ;
61- Ok ( session . take_cookie_value ( ) )
62+ Ok ( cookie_value )
6263 }
6364
6465 async fn destroy_session ( & self , session : & mut Session ) -> Result < ( ) , Self :: Error > {
@@ -116,7 +117,7 @@ mod tests {
116117 session. insert ( "key" , "Hello" ) ?;
117118 let cloned = session. clone ( ) ;
118119 let cookie_value = store. store_session ( & mut session) . await ?. unwrap ( ) ;
119- let loaded_session = store. load_session ( cookie_value) . await ?. unwrap ( ) ;
120+ let loaded_session = store. load_session ( & cookie_value) . await ?. unwrap ( ) ;
120121 assert_eq ! ( cloned. id( ) , loaded_session. id( ) ) ;
121122 assert_eq ! ( "Hello" , & loaded_session. get:: <String >( "key" ) . unwrap( ) ) ;
122123 assert ! ( !loaded_session. is_expired( ) ) ;
@@ -132,11 +133,11 @@ mod tests {
132133 session. insert ( "key" , "value" ) ?;
133134 let cookie_value = store. store_session ( & mut session) . await ?. unwrap ( ) ;
134135
135- let mut session = store. load_session ( cookie_value. clone ( ) ) . await ?. unwrap ( ) ;
136+ let mut session = store. load_session ( & cookie_value) . await ?. unwrap ( ) ;
136137 session. insert ( "key" , "other value" ) ?;
137138
138139 assert_eq ! ( store. store_session( & mut session) . await ?, None ) ;
139- let session = store. load_session ( cookie_value) . await ?. unwrap ( ) ;
140+ let session = store. load_session ( & cookie_value) . await ?. unwrap ( ) ;
140141 assert_eq ! ( & mut session. get:: <String >( "key" ) . unwrap( ) , "other value" ) ;
141142
142143 Ok ( ( ) )
@@ -150,18 +151,18 @@ mod tests {
150151 let original_expires = * session. expiry ( ) . unwrap ( ) ;
151152 let cookie_value = store. store_session ( & mut session) . await ?. unwrap ( ) ;
152153
153- let mut session = store. load_session ( cookie_value. clone ( ) ) . await ?. unwrap ( ) ;
154+ let mut session = store. load_session ( & cookie_value) . await ?. unwrap ( ) ;
154155
155156 assert_eq ! ( session. expiry( ) . unwrap( ) , & original_expires) ;
156157 session. expire_in ( Duration :: from_secs ( 3 ) ) ;
157158 let new_expires = * session. expiry ( ) . unwrap ( ) ;
158159 assert_eq ! ( None , store. store_session( & mut session) . await ?) ;
159160
160- let session = store. load_session ( cookie_value. clone ( ) ) . await ?. unwrap ( ) ;
161+ let session = store. load_session ( & cookie_value) . await ?. unwrap ( ) ;
161162 assert_eq ! ( session. expiry( ) . unwrap( ) , & new_expires) ;
162163
163164 task:: sleep ( Duration :: from_secs ( 3 ) ) . await ;
164- assert_eq ! ( None , store. load_session( cookie_value) . await ?) ;
165+ assert_eq ! ( None , store. load_session( & cookie_value) . await ?) ;
165166
166167 Ok ( ( ) )
167168 }
@@ -176,14 +177,14 @@ mod tests {
176177
177178 let cookie_value = store. store_session ( & mut session) . await ?. unwrap ( ) ;
178179
179- let loaded_session = store. load_session ( cookie_value. clone ( ) ) . await ?. unwrap ( ) ;
180+ let loaded_session = store. load_session ( & cookie_value) . await ?. unwrap ( ) ;
180181 assert_eq ! ( cloned. id( ) , loaded_session. id( ) ) ;
181182 assert_eq ! ( "value" , & * loaded_session. get:: <String >( "key" ) . unwrap( ) ) ;
182183
183184 assert ! ( !loaded_session. is_expired( ) ) ;
184185
185186 task:: sleep ( Duration :: from_secs ( 3 ) ) . await ;
186- assert_eq ! ( None , store. load_session( cookie_value) . await ?) ;
187+ assert_eq ! ( None , store. load_session( & cookie_value) . await ?) ;
187188
188189 Ok ( ( ) )
189190 }
@@ -197,9 +198,9 @@ mod tests {
197198
198199 let cookie = store. store_session ( & mut Session :: new ( ) ) . await ?. unwrap ( ) ;
199200 assert_eq ! ( 4 , store. count( ) ) ;
200- let mut session = store. load_session ( cookie. clone ( ) ) . await ?. unwrap ( ) ;
201+ let mut session = store. load_session ( & cookie) . await ?. unwrap ( ) ;
201202 store. destroy_session ( & mut session) . await ?;
202- assert_eq ! ( None , store. load_session( cookie) . await ?) ;
203+ assert_eq ! ( None , store. load_session( & cookie) . await ?) ;
203204 assert_eq ! ( 3 , store. count( ) ) ;
204205
205206 // attempting to destroy the session again is not an error
0 commit comments