#![no_std]
#![no_implicit_prelude]
extern crate core;
use core::cell::Cell;
use core::fmt::{Debug, Formatter, Result};
use core::iter::IntoIterator;
use core::marker::Sized;
use core::option::Option;
#[cfg(test)]
mod tests;
pub struct IterDebug<T>(Cell<Option<T>>);
impl<T> IterDebug<T> {
#[inline]
pub fn new(item: T) -> Self { Self(Cell::new(Option::Some(item))) }
#[inline]
pub fn try_into_inner(&self) -> Option<T> { self.0.take() }
}
impl<T> Debug for IterDebug<T>
where
T: IntoIterator,
T::Item: Debug,
{
#[inline]
fn fmt(&self, f: &mut Formatter) -> Result {
match self.0.take() {
Option::Some(value) => f.debug_list().entries(value).finish(),
Option::None => f.write_str("<consumed iterator>"),
}
}
}
pub trait DebugIterator {
fn debug(self) -> IterDebug<Self>
where
Self: Sized;
}
impl<T> DebugIterator for T
where
T: IntoIterator,
T::Item: Debug,
{
#[inline]
fn debug(self) -> IterDebug<Self>
where
Self: Sized,
{
IterDebug::new(self)
}
}