@@ -117,6 +117,55 @@ impl<'a> BulkWrite<'a> {
117117 }
118118}
119119
120+ action_impl ! {
121+ impl Action <' a> for BulkWrite <' a> {
122+ type Future = BulkWriteFuture ;
123+
124+ async fn execute( mut self ) -> Result <BulkWriteResult > {
125+ let mut total_attempted = 0 ;
126+ let mut execution_status = ExecutionStatus :: None ;
127+
128+ while total_attempted < self . models. len( )
129+ && execution_status. should_continue( self . is_ordered( ) )
130+ {
131+ let mut operation = BulkWriteOperation :: new(
132+ self . client. clone( ) ,
133+ & self . models[ total_attempted..] ,
134+ total_attempted,
135+ self . options. as_ref( ) ,
136+ )
137+ . await ;
138+ let result = self
139+ . client
140+ . execute_operation:: <BulkWriteOperation >(
141+ & mut operation,
142+ self . session. as_deref_mut( ) ,
143+ )
144+ . await ;
145+ total_attempted += operation. n_attempted;
146+
147+ match result {
148+ Ok ( result) => {
149+ execution_status = execution_status. with_success( result) ;
150+ }
151+ Err ( error) => {
152+ execution_status = execution_status. with_failure( error) ;
153+ }
154+ }
155+ }
156+
157+ match execution_status {
158+ ExecutionStatus :: Success ( bulk_write_result) => Ok ( bulk_write_result) ,
159+ ExecutionStatus :: Error ( error) => Err ( error) ,
160+ ExecutionStatus :: None => Err ( ErrorKind :: InvalidArgument {
161+ message: "bulk_write must be provided at least one write operation" . into( ) ,
162+ }
163+ . into( ) ) ,
164+ }
165+ }
166+ }
167+ }
168+
120169enum ExecutionStatus {
121170 Success ( BulkWriteResult ) ,
122171 Error ( Error ) ,
@@ -155,7 +204,7 @@ impl ExecutionStatus {
155204 let bulk_write_error: Error = ErrorKind :: ClientBulkWrite ( BulkWriteError {
156205 write_errors : HashMap :: new ( ) ,
157206 write_concern_errors : Vec :: new ( ) ,
158- partial_result : Some ( current_result) ,
207+ partial_result : current_result,
159208 } )
160209 . into ( ) ;
161210 Self :: Error ( bulk_write_error. with_source ( error) )
@@ -206,35 +255,3 @@ impl ExecutionStatus {
206255 }
207256 }
208257}
209-
210- action_impl ! {
211- impl Action <' a> for BulkWrite <' a> {
212- type Future = SummaryBulkWrite ;
213-
214- async fn execute( mut self ) -> Result <BulkWriteResult > {
215- let mut total_attempted = 0 ;
216- let mut execution_status = ExecutionStatus :: None ;
217-
218- while total_attempted < self . models. len( ) && execution_status. should_continue( self . is_ordered( ) ) {
219- let mut operation = BulkWriteOperation :: new( self . client. clone( ) , & self . models[ total_attempted..] , total_attempted, self . options. as_ref( ) ) . await ;
220- let result = self . client. execute_operation:: <BulkWriteOperation >( & mut operation, self . session. as_deref_mut( ) ) . await ;
221- total_attempted += operation. n_attempted;
222-
223- match result {
224- Ok ( result) => {
225- execution_status = execution_status. with_success( result) ;
226- }
227- Err ( error) => {
228- execution_status = execution_status. with_failure( error) ;
229- }
230- }
231- }
232-
233- match execution_status {
234- ExecutionStatus :: Success ( bulk_write_result) => Ok ( bulk_write_result) ,
235- ExecutionStatus :: Error ( error) => Err ( error) ,
236- ExecutionStatus :: None => Err ( ErrorKind :: InvalidArgument { message: "bulk_write must be provided at least one write operation" . into( ) } . into( ) )
237- }
238- }
239- }
240- }
0 commit comments