1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use core::fmt::Debug;
use core::iter::FusedIterator;
use core::marker::PhantomData;
pub trait UncheckedEnumerable<I, T, E> {
fn unchecked(self) -> UncheckedIter<I, T, E>;
}
impl<I, T, E> UncheckedEnumerable<I, T, E> for I
where
I: Iterator<Item = Result<T, E>>,
E: Debug,
{
fn unchecked(self) -> UncheckedIter<I, T, E> {
UncheckedIter {
iter: self,
item_type: PhantomData,
error_type: PhantomData,
}
}
}
#[derive(Clone)]
pub struct UncheckedIter<I, T, E> {
iter: I,
item_type: PhantomData<T>,
error_type: PhantomData<E>,
}
impl<I, T, E> Iterator for UncheckedIter<I, T, E>
where
I: Iterator<Item = Result<T, E>>,
E: Debug,
{
type Item = T;
#[inline(always)]
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(Result::unwrap)
}
#[inline(always)]
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}
impl<I, T, E> DoubleEndedIterator for UncheckedIter<I, T, E>
where
I: Iterator<Item = Result<T, E>> + DoubleEndedIterator,
E: Debug,
{
#[inline(always)]
fn next_back(&mut self) -> Option<Self::Item> {
self.iter.next_back().map(Result::unwrap)
}
}
impl<I, T, E> FusedIterator for UncheckedIter<I, T, E>
where
I: Iterator<Item = Result<T, E>> + FusedIterator,
E: Debug,
{
}
impl<I, T, E> ExactSizeIterator for UncheckedIter<I, T, E>
where
I: Iterator<Item = Result<T, E>> + ExactSizeIterator,
E: Debug,
{
#[inline(always)]
fn len(&self) -> usize {
self.iter.len()
}
}