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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#![cfg_attr(feature="unstable", feature(inclusive_range, step_trait))]
#![cfg_attr(not(feature="std"), no_std)]
#[cfg(feature="std")]
extern crate core;
use core::iter::*;
pub unsafe trait UniqueIterator: Iterator where Self::Item: PartialEq
{}
pub unsafe trait AscendingIterator: Iterator where Self::Item: PartialOrd
{}
pub unsafe trait DescendingIterator: Iterator where Self::Item: PartialOrd
{}
unsafe impl<T:PartialEq, I:Iterator<Item=T>> UniqueIterator for Enumerate<I> {}
unsafe impl<T:PartialOrd, I:Iterator<Item=T>> AscendingIterator for Enumerate<I> {}
unsafe impl<T:PartialEq> UniqueIterator for Once<T> {}
unsafe impl<T:PartialOrd> AscendingIterator for Once<T> {}
unsafe impl<T:PartialOrd> DescendingIterator for Once<T> {}
unsafe impl<T:PartialEq> UniqueIterator for Empty<T> {}
unsafe impl<T:PartialOrd> AscendingIterator for Empty<T> {}
unsafe impl<T:PartialOrd> DescendingIterator for Empty<T> {}
#[cfg(feature="unstable")]
mod unstable {
use super::{UniqueIterator,AscendingIterator};
use core::ops::{Range,RangeInclusive, Add};
use core::iter::Step;
unsafe impl<T:PartialEq+Step> UniqueIterator for Range<T> where for<'a> &'a T: Add<&'a T, Output=T> {}
unsafe impl<T:PartialOrd+Step> AscendingIterator for Range<T> where for<'a> &'a T: Add<&'a T, Output=T> {}
unsafe impl<T:PartialEq+Step> UniqueIterator for RangeInclusive<T> where for<'a> &'a T: Add<&'a T, Output=T> {}
unsafe impl<T:PartialOrd+Step> AscendingIterator for RangeInclusive<T> where for<'a> &'a T: Add<&'a T, Output=T> {}
}
#[cfg(feature="unstable")]
pub use unstable::*;
#[cfg(feature="std")]
mod collections {
use super::{UniqueIterator,AscendingIterator};
use std::collections::{hash_map, btree_map, hash_set, btree_set};
use std::hash::{Hash, BuildHasher};
unsafe impl<'a, K:Eq, V> UniqueIterator for hash_map::Keys<'a,K,V> {}
unsafe impl<'a, K:Eq, V:PartialEq> UniqueIterator for hash_map::Iter<'a,K,V> {}
unsafe impl<'a, K:Eq, V:PartialEq> UniqueIterator for hash_map::IterMut<'a,K,V> {}
unsafe impl<K:Eq, V:PartialEq> UniqueIterator for hash_map::IntoIter<K,V> {}
unsafe impl<'a, K:Ord, V> UniqueIterator for btree_map::Keys<'a,K,V> {}
unsafe impl<'a, K:Ord, V:PartialEq> UniqueIterator for btree_map::Iter<'a,K,V> {}
unsafe impl<'a, K:Ord, V:PartialEq> UniqueIterator for btree_map::IterMut<'a,K,V> {}
unsafe impl<K:Ord, V:PartialEq> UniqueIterator for btree_map::IntoIter<K,V> {}
unsafe impl<'a, K:Ord, V> AscendingIterator for btree_map::Keys<'a,K,V> {}
unsafe impl<'a, K:Ord, V:PartialOrd> AscendingIterator for btree_map::Iter<'a,K,V> {}
unsafe impl<'a, K:Ord, V:PartialOrd> AscendingIterator for btree_map::IterMut<'a,K,V> {}
unsafe impl<K:Ord, V:PartialOrd> AscendingIterator for btree_map::IntoIter<K,V> {}
unsafe impl<T:Eq> UniqueIterator for hash_set::IntoIter<T> {}
unsafe impl<'a, T:Eq+Hash> UniqueIterator for hash_set::Iter<'a,T> {}
unsafe impl<'a, T:Eq+Hash, S:BuildHasher> UniqueIterator for hash_set::Union<'a,T,S> {}
unsafe impl<'a, T:Eq+Hash, S:BuildHasher> UniqueIterator for hash_set::Intersection<'a,T,S> {}
unsafe impl<'a, T:Eq+Hash, S:BuildHasher> UniqueIterator for hash_set::Difference<'a,T,S> {}
unsafe impl<'a, T:Eq+Hash, S:BuildHasher> UniqueIterator for hash_set::SymmetricDifference<'a,T,S> {}
unsafe impl<T:Ord> UniqueIterator for btree_set::IntoIter<T> {}
unsafe impl<'a, T:Ord> UniqueIterator for btree_set::Iter<'a,T> {}
unsafe impl<'a, T:Ord> UniqueIterator for btree_set::Intersection<'a,T> {}
unsafe impl<'a, T:Ord> UniqueIterator for btree_set::Union<'a,T> {}
unsafe impl<'a, T:Ord> UniqueIterator for btree_set::Difference<'a,T> {}
unsafe impl<'a, T:Ord> UniqueIterator for btree_set::SymmetricDifference<'a,T> {}
unsafe impl<T:Ord> AscendingIterator for btree_set::IntoIter<T> {}
unsafe impl<'a, T:Ord> AscendingIterator for btree_set::Iter<'a,T> {}
unsafe impl<'a, T:Ord> AscendingIterator for btree_set::Intersection<'a,T> {}
}
#[cfg(feature="std")]
pub use collections::*;
macro_rules! it {($i:item) => {$i}}
macro_rules! simple_iter {($bound:tt, $marker:tt: $($typ:tt)*) => {
$(it!{unsafe impl<T:$bound, I:Iterator<Item=T>+$marker> $marker for $typ<I> {}})*
}}
macro_rules! filter_iter {($bound:tt, $marker:tt: $($typ:tt)*) => {
$(it!{unsafe impl<T:$bound, I:Iterator<Item=T>+$marker, F:FnMut(&T)->bool> $marker for $typ<I,F> {}})*
}}
simple_iter!{PartialEq, UniqueIterator: Peekable Skip Take Fuse}
simple_iter!{PartialOrd, AscendingIterator: Peekable Skip Take Fuse}
simple_iter!{PartialOrd, DescendingIterator: Peekable Skip Take Fuse}
filter_iter!{PartialEq, UniqueIterator: Filter SkipWhile TakeWhile}
filter_iter!{PartialOrd, AscendingIterator: Filter SkipWhile TakeWhile}
filter_iter!{PartialOrd, DescendingIterator: Filter SkipWhile TakeWhile}
unsafe impl<I:DoubleEndedIterator+UniqueIterator> UniqueIterator for Rev<I> where I::Item: PartialOrd {}
unsafe impl<I:DoubleEndedIterator+AscendingIterator> DescendingIterator for Rev<I> where I::Item: PartialOrd {}
unsafe impl<I:DoubleEndedIterator+DescendingIterator> AscendingIterator for Rev<I> where I::Item: PartialOrd {}
unsafe impl<'a, T:'a+Clone+PartialEq, I:Iterator<Item=&'a T>+UniqueIterator> UniqueIterator for Cloned<I> {}
unsafe impl<'a, T:'a+Clone+PartialOrd, I:Iterator<Item=&'a T>+AscendingIterator> AscendingIterator for Cloned<I> {}
unsafe impl<'a, T:'a+Clone+PartialOrd, I:Iterator<Item=&'a T>+DescendingIterator> DescendingIterator for Cloned<I> {}
unsafe impl<T:PartialEq, I:Iterator<Item=T>+UniqueIterator, F:FnMut(&T)> UniqueIterator for Inspect<I,F> {}
unsafe impl<T:PartialOrd, I:Iterator<Item=T>+AscendingIterator, F:FnMut(&T)> AscendingIterator for Inspect<I,F> {}
unsafe impl<T:PartialOrd, I:Iterator<Item=T>+DescendingIterator, F:FnMut(&T)> DescendingIterator for Inspect<I,F> {}
unsafe impl<TA,TB,IA,IB> UniqueIterator for Zip<IA,IB>
where TA:PartialEq, IA:Iterator<Item=TA>+UniqueIterator,
TB:PartialEq, IB:Iterator<Item=TB>
{}
unsafe impl<TA,TB,IA,IB> AscendingIterator for Zip<IA,IB>
where TA:PartialOrd, IA:Iterator<Item=TA>+AscendingIterator+UniqueIterator,
TB:PartialOrd, IB:Iterator<Item=TB>
{}
unsafe impl<TA,TB,IA,IB> DescendingIterator for Zip<IA,IB>
where TA:PartialOrd, IA:Iterator<Item=TA>+DescendingIterator+UniqueIterator,
TB:PartialOrd, IB:Iterator<Item=TB>
{}