@@ -289,6 +289,35 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
289
289
} ;
290
290
}
291
291
292
+ fn try_fold < B , F , R > ( & mut self , init : B , mut f : F ) -> R
293
+ where
294
+ Self : Sized ,
295
+ F : FnMut ( B , Self :: Item ) -> R ,
296
+ R : core:: ops:: Try < Output = B > ,
297
+ {
298
+ let mut accum = init;
299
+ if T :: IS_ZST {
300
+ while self . ptr . as_ptr ( ) != self . end . cast_mut ( ) {
301
+ // SAFETY: we just checked that `self.ptr` is in bounds.
302
+ let tmp = unsafe { self . ptr . read ( ) } ;
303
+ // See `next` for why we subtract from `end` here.
304
+ self . end = self . end . wrapping_byte_sub ( 1 ) ;
305
+ accum = f ( accum, tmp) ?;
306
+ }
307
+ } else {
308
+ // SAFETY: `self.end` can only be null if `T` is a ZST.
309
+ while self . ptr != non_null ! ( self . end, T ) {
310
+ // SAFETY: we just checked that `self.ptr` is in bounds.
311
+ let tmp = unsafe { self . ptr . read ( ) } ;
312
+ // SAFETY: the maximum this can be is `self.end`.
313
+ // Increment `self.ptr` first to avoid double dropping in the event of a panic.
314
+ self . ptr = unsafe { self . ptr . add ( 1 ) } ;
315
+ accum = f ( accum, tmp) ?;
316
+ }
317
+ }
318
+ R :: from_output ( accum)
319
+ }
320
+
292
321
unsafe fn __iterator_get_unchecked ( & mut self , i : usize ) -> Self :: Item
293
322
where
294
323
Self : TrustedRandomAccessNoCoerce ,
0 commit comments