@@ -441,33 +441,14 @@ pub struct IntoIter<T, const N: usize> {
441
441
// FIXME: Once the fix for https://github.com/rust-embedded/heapless/issues/530 is released. We
442
442
// can turn this into a wrapper around `heapless::vec::IntoIter`.
443
443
#[ cfg( not( feature = "alloc" ) ) ]
444
- vec : heapless:: Vec < T , N > ,
445
- #[ cfg( not( feature = "alloc" ) ) ]
446
- next : usize ,
444
+ iter : heapless:: vec:: IntoIter < T , N , usize > ,
447
445
}
448
446
449
447
impl < T , const N : usize > Iterator for IntoIter < T , N > {
450
448
type Item = T ;
451
449
#[ inline]
452
450
fn next ( & mut self ) -> Option < Self :: Item > {
453
- #[ cfg( feature = "alloc" ) ]
454
- {
455
- self . iter . next ( )
456
- }
457
- #[ cfg( not( feature = "alloc" ) ) ]
458
- {
459
- if self . next < self . vec . len ( ) {
460
- // SAFETY:
461
- // * `next` is always less than `len`.
462
- // * `<*const T>::add` takes `size_of::<T>()` into account so the pointer returned
463
- // by it will be aligned correctly (which is assumed by `ptr::read`).
464
- let item = unsafe { ( self . vec . as_ptr ( ) . add ( self . next ) ) . read ( ) } ;
465
- self . next += 1 ;
466
- Some ( item)
467
- } else {
468
- None
469
- }
470
- }
451
+ self . iter . next ( )
471
452
}
472
453
}
473
454
@@ -478,24 +459,7 @@ impl<T, const N: usize> IntoIterator for Vec<T, N> {
478
459
#[ inline]
479
460
fn into_iter ( self ) -> Self :: IntoIter {
480
461
IntoIter {
481
- #[ cfg( feature = "alloc" ) ]
482
462
iter : self . 0 . into_iter ( ) ,
483
- #[ cfg( not( feature = "alloc" ) ) ]
484
- vec : self . 0 ,
485
- #[ cfg( not( feature = "alloc" ) ) ]
486
- next : 0 ,
487
- }
488
- }
489
- }
490
-
491
- #[ cfg( not( feature = "alloc" ) ) ]
492
- impl < T , const N : usize > Drop for IntoIter < T , N > {
493
- fn drop ( & mut self ) {
494
- unsafe {
495
- // Drop all the elements that have not been moved out of vec
496
- core:: ptr:: drop_in_place ( & mut self . vec . as_mut_slice ( ) [ self . next ..] ) ;
497
- // Prevent dropping of other elements
498
- self . vec . set_len ( 0 ) ;
499
463
}
500
464
}
501
465
}
0 commit comments