1use crate::SingleItemStorage;
2#[cfg(feature = "alloc")]
3use alloc::{string::String, vec::Vec};
4use core::{option, slice};
5
6pub trait Iter {
8 type Output<'iter>: Iterator
10 where
11 Self: 'iter;
12
13 fn iter(&self) -> Self::Output<'_>;
15}
16
17impl<T> Iter for &T
18where
19 T: Iter,
20{
21 type Output<'iter>
22 = T::Output<'iter>
23 where
24 Self: 'iter;
25
26 #[inline]
27 fn iter(&self) -> Self::Output<'_> {
28 (*self).iter()
29 }
30}
31
32impl Iter for () {
36 type Output<'iter> = slice::Iter<'iter, ()>;
37
38 #[inline]
39 fn iter(&self) -> Self::Output<'_> {
40 [].as_ref().iter()
41 }
42}
43
44impl<T> Iter for Option<T> {
48 type Output<'iter>
49 = option::Iter<'iter, T>
50 where
51 T: 'iter;
52
53 #[inline]
54 fn iter(&self) -> Self::Output<'_> {
55 self.iter()
56 }
57}
58
59impl<T> Iter for SingleItemStorage<T> {
64 type Output<'iter>
65 = slice::Iter<'iter, T>
66 where
67 T: 'iter;
68
69 #[inline]
70 fn iter(&self) -> Self::Output<'_> {
71 slice::from_ref(&self.0).iter()
72 }
73}
74
75impl<T, const N: usize> Iter for [T; N] {
80 type Output<'iter>
81 = slice::Iter<'iter, T>
82 where
83 T: 'iter;
84
85 #[inline]
86 fn iter(&self) -> Self::Output<'_> {
87 self.as_ref().iter()
88 }
89}
90
91impl<T> Iter for &'_ [T] {
96 type Output<'iter>
97 = slice::Iter<'iter, T>
98 where
99 Self: 'iter;
100
101 #[inline]
102 fn iter(&self) -> Self::Output<'_> {
103 self.as_ref().iter()
104 }
105}
106
107#[cfg(feature = "alloc")]
112impl Iter for String {
113 type Output<'iter> = core::str::Chars<'iter>;
114
115 #[inline]
116 fn iter(&self) -> Self::Output<'_> {
117 self.chars()
118 }
119}
120
121#[cfg(feature = "alloc")]
126impl<T> Iter for Vec<T> {
127 type Output<'iter>
128 = slice::Iter<'iter, T>
129 where
130 T: 'iter;
131
132 #[inline]
133 fn iter(&self) -> Self::Output<'_> {
134 self.as_slice().iter()
135 }
136}
137
138#[cfg(feature = "arrayvec")]
143impl<const N: usize> Iter for arrayvec::ArrayString<N> {
144 type Output<'iter> = core::str::Chars<'iter>;
145
146 #[inline]
147 fn iter(&self) -> Self::Output<'_> {
148 self.chars()
149 }
150}
151
152#[cfg(feature = "arrayvec")]
157impl<T, const N: usize> Iter for arrayvec::ArrayVec<T, N> {
158 type Output<'iter>
159 = slice::Iter<'iter, T>
160 where
161 T: 'iter;
162
163 #[inline]
164 fn iter(&self) -> Self::Output<'_> {
165 self.as_slice().iter()
166 }
167}
168
169#[cfg(feature = "smallvec")]
174impl<A> Iter for smallvec::SmallVec<A>
175where
176 A: smallvec::Array,
177{
178 type Output<'iter>
179 = slice::Iter<'iter, A::Item>
180 where
181 A: 'iter;
182
183 #[inline]
184 fn iter(&self) -> Self::Output<'_> {
185 self.as_slice().iter()
186 }
187}
188
189#[cfg(feature = "tinyvec")]
194impl<A> Iter for tinyvec::ArrayVec<A>
195where
196 A: tinyvec::Array,
197 A::Item: Default,
198{
199 type Output<'iter>
200 = slice::Iter<'iter, A::Item>
201 where
202 A: 'iter;
203
204 #[inline]
205 fn iter(&self) -> Self::Output<'_> {
206 self.as_slice().iter()
207 }
208}
209
210#[cfg(all(feature = "alloc", feature = "tinyvec"))]
215impl<A> Iter for tinyvec::TinyVec<A>
216where
217 A: tinyvec::Array,
218 A::Item: Default,
219{
220 type Output<'iter>
221 = slice::Iter<'iter, A::Item>
222 where
223 A: 'iter;
224
225 #[inline]
226 fn iter(&self) -> Self::Output<'_> {
227 self.as_slice().iter()
228 }
229}