Merge pull request #54 from Nemo157/intoiter-debug

impl Debug for {Tiny,Array}VecIterator
This commit is contained in:
Lokathor
2020-01-26 12:38:00 -07:00
committed by GitHub
2 changed files with 31 additions and 0 deletions
+14
View File
@@ -814,6 +814,14 @@ pub struct ArrayVecIterator<A: Array> {
len: usize,
data: A,
}
impl<A: Array> ArrayVecIterator<A> {
/// 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<A: Array> Iterator for ArrayVecIterator<A> {
type Item = A::Item;
#[inline]
@@ -853,6 +861,12 @@ impl<A: Array> Iterator for ArrayVecIterator<A> {
}
}
impl<A: Array> Debug for ArrayVecIterator<A> where A::Item: Debug {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.debug_tuple("ArrayVecIterator").field(&self.as_slice()).finish()
}
}
impl<A: Array> IntoIterator for ArrayVec<A> {
type Item = A::Item;
type IntoIter = ArrayVecIterator<A>;
+17
View File
@@ -715,6 +715,17 @@ pub enum TinyVecIterator<A: Array> {
#[allow(missing_docs)]
Heap(alloc::vec::IntoIter<A::Item>),
}
impl<A: Array> TinyVecIterator<A> {
/// 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<A: Array> Iterator for TinyVecIterator<A> {
type Item = A::Item;
#[inline]
@@ -755,6 +766,12 @@ impl<A: Array> Iterator for TinyVecIterator<A> {
}
}
impl<A: Array> Debug for TinyVecIterator<A> where A::Item: Debug {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.debug_tuple("TinyVecIterator").field(&self.as_slice()).finish()
}
}
impl<A: Array> IntoIterator for TinyVec<A> {
type Item = A::Item;
type IntoIter = TinyVecIterator<A>;