@@ -7,16 +7,16 @@ use crate::SessionIdentifier;
77pub ( crate ) struct SessionInner < T > {
88 /// The current, active session
99 current : Option < ActiveSession < T > > ,
10- /// The ID of the original session if deleted during the request
11- deleted : Option < String > ,
10+ /// The original session if deleted during the request
11+ deleted : Option < ActiveSession < T > > ,
1212}
1313impl < T > Default for SessionInner < T > {
1414 fn default ( ) -> Self {
1515 Self :: new_empty ( )
1616 }
1717}
1818
19- /// Represents a current, active session
19+ /// Represents an active session
2020#[ derive( Debug ) ]
2121struct ActiveSession < T > {
2222 /// Session ID (20-character alphanumeric string)
@@ -156,28 +156,28 @@ impl<T> SessionInner<T> {
156156 }
157157 }
158158
159- /// Mark the current session ID as deleted, and clear all data. Can safely be called
159+ /// Mark the current session as deleted, and clear all data. Can safely be called
160160 /// multiple times in a request if needed - the original session will still be deleted.
161161 pub ( crate ) fn delete ( & mut self ) {
162162 if let Some ( current) = self . current . take ( ) {
163- self . deleted . get_or_insert ( current. id ) ;
163+ self . deleted . get_or_insert ( current) ;
164164 }
165165 }
166166
167167 pub ( crate ) fn get_deleted_id ( & self ) -> Option < & str > {
168- self . deleted . as_deref ( )
168+ self . deleted . as_ref ( ) . map ( |s| s . id . as_str ( ) )
169169 }
170170
171171 /// Get all data for storage if the session needs to be saved/updated. Returns a tuple of Options
172- /// representing an updated session along with the id of a deleted session. This should only be
173- /// called once at the end of the request, as it takes ownership of the session data.
174- pub ( crate ) fn take_for_storage ( & mut self ) -> ( Option < ( String , T , u32 ) > , Option < String > ) {
172+ /// representing an updated session along with a deleted session. This should only be
173+ /// called once at the end of the request, as it takes ownership of all data.
174+ pub ( crate ) fn take_for_storage ( & mut self ) -> ( Option < ( String , T , u32 ) > , Option < ( String , T ) > ) {
175175 let updated_session = self
176176 . current
177177 . take ( )
178178 . filter ( |c| should_save_session ( & c. status ) )
179179 . map ( |c| ( c. id , c. data , c. ttl ) ) ;
180- ( updated_session, self . deleted . take ( ) )
180+ ( updated_session, self . deleted . take ( ) . map ( |s| ( s . id , s . data ) ) )
181181 }
182182}
183183
0 commit comments