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