From 109e9b6e612cb536c76f7c4dcba3be93f59a62e2 Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Fri, 24 Jan 2020 14:39:46 +0100 Subject: [PATCH] impl Debug for {Tiny,Array}VecIterator --- src/arrayvec.rs | 14 ++++++++++++++ src/tinyvec.rs | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) 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 ab4e5e4..f313a39 100644 --- a/src/tinyvec.rs +++ b/src/tinyvec.rs @@ -684,6 +684,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] @@ -724,6 +735,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;