@@ -289,6 +289,60 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
289289 } ;
290290 }
291291
292+ fn fold < B , F > ( mut self , mut accum : B , mut f : F ) -> B
293+ where
294+ F : FnMut ( B , Self :: Item ) -> B ,
295+ {
296+ if T :: IS_ZST {
297+ while self . ptr . as_ptr ( ) != self . end . cast_mut ( ) {
298+ // SAFETY: we just checked that `self.ptr` is in bounds.
299+ let tmp = unsafe { self . ptr . read ( ) } ;
300+ // See `next` for why we subtract from `end` here.
301+ self . end = self . end . wrapping_byte_sub ( 1 ) ;
302+ accum = f ( accum, tmp) ;
303+ }
304+ } else {
305+ // SAFETY: `self.end` can only be null if `T` is a ZST.
306+ while self . ptr != non_null ! ( self . end, T ) {
307+ // SAFETY: we just checked that `self.ptr` is in bounds.
308+ let tmp = unsafe { self . ptr . read ( ) } ;
309+ // SAFETY: the maximum this can be is `self.end`.
310+ // Increment `self.ptr` first to avoid double dropping in the event of a panic.
311+ self . ptr = unsafe { self . ptr . add ( 1 ) } ;
312+ accum = f ( accum, tmp) ;
313+ }
314+ }
315+ accum
316+ }
317+
318+ fn try_fold < B , F , R > ( & mut self , mut accum : B , mut f : F ) -> R
319+ where
320+ Self : Sized ,
321+ F : FnMut ( B , Self :: Item ) -> R ,
322+ R : core:: ops:: Try < Output = B > ,
323+ {
324+ if T :: IS_ZST {
325+ while self . ptr . as_ptr ( ) != self . end . cast_mut ( ) {
326+ // SAFETY: we just checked that `self.ptr` is in bounds.
327+ let tmp = unsafe { self . ptr . read ( ) } ;
328+ // See `next` for why we subtract from `end` here.
329+ self . end = self . end . wrapping_byte_sub ( 1 ) ;
330+ accum = f ( accum, tmp) ?;
331+ }
332+ } else {
333+ // SAFETY: `self.end` can only be null if `T` is a ZST.
334+ while self . ptr != non_null ! ( self . end, T ) {
335+ // SAFETY: we just checked that `self.ptr` is in bounds.
336+ let tmp = unsafe { self . ptr . read ( ) } ;
337+ // SAFETY: the maximum this can be is `self.end`.
338+ // Increment `self.ptr` first to avoid double dropping in the event of a panic.
339+ self . ptr = unsafe { self . ptr . add ( 1 ) } ;
340+ accum = f ( accum, tmp) ?;
341+ }
342+ }
343+ R :: from_output ( accum)
344+ }
345+
292346 unsafe fn __iterator_get_unchecked ( & mut self , i : usize ) -> Self :: Item
293347 where
294348 Self : TrustedRandomAccessNoCoerce ,
0 commit comments