Skip to content

Commit ba14538

Browse files
committed
🔥 Drop a now redundant workaround for heapless 0.8
1 parent 90cc3d5 commit ba14538

File tree

1 file changed

+2
-38
lines changed

1 file changed

+2
-38
lines changed

‎src/vec.rs

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -441,33 +441,14 @@ pub struct IntoIter<T, const N: usize> {
441441
// FIXME: Once the fix for https://github.com/rust-embedded/heapless/issues/530 is released. We
442442
// can turn this into a wrapper around `heapless::vec::IntoIter`.
443443
#[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>,
447445
}
448446

449447
impl<T, const N: usize> Iterator for IntoIter<T, N> {
450448
type Item = T;
451449
#[inline]
452450
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()
471452
}
472453
}
473454

@@ -478,24 +459,7 @@ impl<T, const N: usize> IntoIterator for Vec<T, N> {
478459
#[inline]
479460
fn into_iter(self) -> Self::IntoIter {
480461
IntoIter {
481-
#[cfg(feature = "alloc")]
482462
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);
499463
}
500464
}
501465
}

0 commit comments

Comments
 (0)