@@ -10,7 +10,7 @@ use futures::{Future, Stream};
1010
1111use crate :: {
1212 bson:: Document ,
13- error:: { ErrorKind , Result } ,
13+ error:: { Error , ErrorKind , Result } ,
1414 options:: StreamAddress ,
1515 results:: GetMoreResult ,
1616 Client ,
@@ -73,12 +73,13 @@ impl<T: GetMoreProvider> Stream for GenericCursor<T> {
7373 if let Some ( future) = self . provider . executing_future ( ) {
7474 match Pin :: new ( future) . poll ( cx) {
7575 // If a result is ready, retrieve the buffer and update the exhausted status.
76- Poll :: Ready ( mut get_more_result) => {
77- let buffer_result = get_more_result. take_buffer ( ) ;
78- self . exhausted = get_more_result. exhausted ( ) ;
76+ Poll :: Ready ( get_more_result) => {
77+ let exhausted = get_more_result. exhausted ( ) ;
78+ let ( result , session ) = get_more_result. into_parts ( ) ;
7979
80- self . provider . clear_execution ( get_more_result) ;
81- self . buffer = buffer_result?;
80+ self . exhausted = exhausted;
81+ self . provider . clear_execution ( session, exhausted) ;
82+ self . buffer = result?. batch ;
8283 }
8384 Poll :: Pending => return Poll :: Pending ,
8485 }
@@ -113,24 +114,23 @@ pub(super) trait GetMoreProvider: Unpin {
113114 fn executing_future ( & mut self ) -> Option < & mut Self :: GetMoreFuture > ;
114115
115116 /// Clear out any state remaining from previous getMore executions.
116- fn clear_execution ( & mut self , result : Self :: GetMoreResult ) ;
117+ fn clear_execution (
118+ & mut self ,
119+ session : <Self :: GetMoreResult as GetMoreProviderResult >:: Session ,
120+ exhausted : bool ,
121+ ) ;
117122
118123 /// Start executing a new getMore if one isn't already in flight.
119124 fn start_execution ( & mut self , spec : CursorInformation , client : Client ) ;
120125}
121126
122127/// Trait describing results returned from a `GetMoreProvider`.
123128pub ( super ) trait GetMoreProviderResult {
124- /// A result containing a mutable reference to the raw getMore result.
125- fn as_mut ( & mut self ) -> Result < & mut GetMoreResult > ;
129+ type Session ;
126130
127- /// A result containing a reference to the raw getMore result.
128- fn as_ref ( & self ) -> Result < & GetMoreResult > ;
131+ fn as_ref ( & self ) -> std:: result:: Result < & GetMoreResult , & Error > ;
129132
130- /// Take the buffer from the getMore result.
131- fn take_buffer ( & mut self ) -> Result < VecDeque < Document > > {
132- self . as_mut ( ) . map ( |res| std:: mem:: take ( & mut res. batch ) )
133- }
133+ fn into_parts ( self ) -> ( Result < GetMoreResult > , Self :: Session ) ;
134134
135135 /// Whether the response from the server indicated the cursor was exhausted or not.
136136 fn exhausted ( & self ) -> bool {
0 commit comments