use crate::SingleItemStorage;
#[cfg(feature = "alloc")]
use alloc::{string::String, vec::Vec};
use core::{option, slice};
pub trait Iter {
type Output<'iter>: Iterator
where
Self: 'iter;
fn iter(&self) -> Self::Output<'_>;
}
impl<T> Iter for &T
where
T: Iter,
{
type Output<'iter>
= T::Output<'iter>
where
Self: 'iter;
#[inline]
fn iter(&self) -> Self::Output<'_> {
(*self).iter()
}
}
impl Iter for () {
type Output<'iter> = slice::Iter<'iter, ()>;
#[inline]
fn iter(&self) -> Self::Output<'_> {
[].as_ref().iter()
}
}
impl<T> Iter for Option<T> {
type Output<'iter>
= option::Iter<'iter, T>
where
T: 'iter;
#[inline]
fn iter(&self) -> Self::Output<'_> {
self.iter()
}
}
impl<T> Iter for SingleItemStorage<T> {
type Output<'iter>
= slice::Iter<'iter, T>
where
T: 'iter;
#[inline]
fn iter(&self) -> Self::Output<'_> {
slice::from_ref(&self.0).iter()
}
}
impl<T, const N: usize> Iter for [T; N] {
type Output<'iter>
= slice::Iter<'iter, T>
where
T: 'iter;
#[inline]
fn iter(&self) -> Self::Output<'_> {
self.as_ref().iter()
}
}
impl<T> Iter for &'_ [T] {
type Output<'iter>
= slice::Iter<'iter, T>
where
Self: 'iter;
#[inline]
fn iter(&self) -> Self::Output<'_> {
self.as_ref().iter()
}
}
#[cfg(feature = "alloc")]
impl Iter for String {
type Output<'iter> = core::str::Chars<'iter>;
#[inline]
fn iter(&self) -> Self::Output<'_> {
self.chars()
}
}
#[cfg(feature = "alloc")]
impl<T> Iter for Vec<T> {
type Output<'iter>
= slice::Iter<'iter, T>
where
T: 'iter;
#[inline]
fn iter(&self) -> Self::Output<'_> {
self.as_slice().iter()
}
}
#[cfg(feature = "arrayvec")]
impl<const N: usize> Iter for arrayvec::ArrayString<N> {
type Output<'iter> = core::str::Chars<'iter>;
#[inline]
fn iter(&self) -> Self::Output<'_> {
self.chars()
}
}
#[cfg(feature = "arrayvec")]
impl<T, const N: usize> Iter for arrayvec::ArrayVec<T, N> {
type Output<'iter>
= slice::Iter<'iter, T>
where
T: 'iter;
#[inline]
fn iter(&self) -> Self::Output<'_> {
self.as_slice().iter()
}
}
#[cfg(feature = "smallvec")]
impl<A> Iter for smallvec::SmallVec<A>
where
A: smallvec::Array,
{
type Output<'iter>
= slice::Iter<'iter, A::Item>
where
A: 'iter;
#[inline]
fn iter(&self) -> Self::Output<'_> {
self.as_slice().iter()
}
}
#[cfg(feature = "tinyvec")]
impl<A> Iter for tinyvec::ArrayVec<A>
where
A: tinyvec::Array,
A::Item: Default,
{
type Output<'iter>
= slice::Iter<'iter, A::Item>
where
A: 'iter;
#[inline]
fn iter(&self) -> Self::Output<'_> {
self.as_slice().iter()
}
}
#[cfg(all(feature = "alloc", feature = "tinyvec"))]
impl<A> Iter for tinyvec::TinyVec<A>
where
A: tinyvec::Array,
A::Item: Default,
{
type Output<'iter>
= slice::Iter<'iter, A::Item>
where
A: 'iter;
#[inline]
fn iter(&self) -> Self::Output<'_> {
self.as_slice().iter()
}
}