use core::{iter::FusedIterator, panic};
use crate::SizeHint;
pub struct TestIterator<T = ()> {
size_hint: (usize, Option<usize>),
_marker: core::marker::PhantomData<T>,
}
impl<T> TestIterator<T> {
#[must_use]
pub const fn new(size_hint: (usize, Option<usize>)) -> Self {
Self { size_hint, _marker: core::marker::PhantomData }
}
#[must_use]
pub const fn exact(len: usize) -> Self {
Self::new((len, Some(len)))
}
#[must_use]
pub const fn invalid() -> Self {
Self::INVALID
}
pub const UNIVERSAL: Self = Self::new(SizeHint::UNIVERSAL.as_hint());
pub const ZERO: Self = Self::new(SizeHint::ZERO.as_hint());
pub const INVALID: Self = Self::new((10, Some(5)));
}
impl<T> Iterator for TestIterator<T> {
type Item = T;
fn size_hint(&self) -> (usize, Option<usize>) {
self.size_hint
}
fn next(&mut self) -> Option<Self::Item> {
unimplemented!("TestIterator is not iteratable");
}
}
impl<T> FusedIterator for TestIterator<T> {}
impl<T> ExactSizeIterator for TestIterator<T> {
fn len(&self) -> usize {
match self.size_hint() {
(lower, Some(upper)) if lower == upper => lower,
_ => panic!("Inexact size hint"),
}
}
}
impl<T> DoubleEndedIterator for TestIterator<T> {
fn next_back(&mut self) -> Option<Self::Item> {
unimplemented!("TestIterator is not iteratable");
}
}