use crate::{Array, ArrayWrapper};
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::vec::Vec;
pub trait Length {
type Output;
fn length(&self) -> Self::Output;
}
impl<T> Length for Option<T> {
type Output = usize;
#[inline]
fn length(&self) -> Self::Output {
if self.is_some() {
1
} else {
0
}
}
}
impl<'a, T> Length for &'a [T] {
type Output = usize;
#[inline]
fn length(&self) -> Self::Output {
self.len()
}
}
impl<'a, T> Length for &'a mut [T] {
type Output = usize;
#[inline]
fn length(&self) -> Self::Output {
self.len()
}
}
impl<A> Length for ArrayWrapper<A>
where
A: Array,
{
type Output = usize;
#[inline]
fn length(&self) -> Self::Output {
self.array.slice().len()
}
}
#[cfg(feature = "alloc")]
impl<T> Length for Vec<T> {
type Output = usize;
#[inline]
fn length(&self) -> Self::Output {
self.len()
}
}
#[cfg(feature = "with-arrayvec")]
impl<A> Length for arrayvec::ArrayVec<A>
where
A: arrayvec::Array,
{
type Output = usize;
#[inline]
fn length(&self) -> Self::Output {
self.len()
}
}
#[cfg(feature = "with-smallvec")]
impl<A> Length for smallvec::SmallVec<A>
where
A: smallvec::Array,
{
type Output = usize;
#[inline]
fn length(&self) -> Self::Output {
self.len()
}
}
#[cfg(feature = "with-staticvec")]
impl<T, const N: usize> Length for staticvec::StaticVec<T, N> {
type Output = usize;
#[inline]
fn length(&self) -> Self::Output {
self.len()
}
}
#[cfg(feature = "with-tinyvec")]
impl<A> Length for tinyvec::ArrayVec<A>
where
A: tinyvec::Array,
A::Item: Default,
{
type Output = usize;
#[inline]
fn length(&self) -> Self::Output {
self.len()
}
}
#[cfg(all(feature = "alloc", feature = "with-tinyvec"))]
impl<A> Length for tinyvec::TinyVec<A>
where
A: tinyvec::Array,
A::Item: Default,
{
type Output = usize;
#[inline]
fn length(&self) -> Self::Output {
self.len()
}
}