diff --git a/src/arrayvec.rs b/src/arrayvec.rs index 5c75b14..8864a42 100644 --- a/src/arrayvec.rs +++ b/src/arrayvec.rs @@ -814,6 +814,14 @@ pub struct ArrayVecIterator { len: usize, data: A, } + +impl ArrayVecIterator { + /// Returns the remaining items of this iterator as a slice. + pub fn as_slice(&self) -> &[A::Item] { + &self.data.as_slice()[self.base..self.len] + } +} + impl Iterator for ArrayVecIterator { type Item = A::Item; #[inline] @@ -853,6 +861,12 @@ impl Iterator for ArrayVecIterator { } } +impl Debug for ArrayVecIterator where A::Item: Debug { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { + f.debug_tuple("ArrayVecIterator").field(&self.as_slice()).finish() + } +} + impl IntoIterator for ArrayVec { type Item = A::Item; type IntoIter = ArrayVecIterator; diff --git a/src/tinyvec.rs b/src/tinyvec.rs index ef59ae8..9a470d9 100644 --- a/src/tinyvec.rs +++ b/src/tinyvec.rs @@ -715,6 +715,17 @@ pub enum TinyVecIterator { #[allow(missing_docs)] Heap(alloc::vec::IntoIter), } + +impl TinyVecIterator { + /// Returns the remaining items of this iterator as a slice. + pub fn as_slice(&self) -> &[A::Item] { + match self { + TinyVecIterator::Inline(a) => a.as_slice(), + TinyVecIterator::Heap(v) => v.as_slice(), + } + } +} + impl Iterator for TinyVecIterator { type Item = A::Item; #[inline] @@ -755,6 +766,12 @@ impl Iterator for TinyVecIterator { } } +impl Debug for TinyVecIterator where A::Item: Debug { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { + f.debug_tuple("TinyVecIterator").field(&self.as_slice()).finish() + } +} + impl IntoIterator for TinyVec { type Item = A::Item; type IntoIter = TinyVecIterator;