use crate::ArrayWrapper;
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::vec::Vec;
pub trait WithCapacity {
type Input;
fn with_capacity(input: Self::Input) -> Self;
}
impl<A> WithCapacity for ArrayWrapper<A>
where
A: crate::Array,
A::Item: Default,
{
type Input = usize;
#[inline]
fn with_capacity(_: Self::Input) -> Self {
ArrayWrapper::default()
}
}
impl<T> WithCapacity for Option<T> {
type Input = usize;
#[inline]
fn with_capacity(_: Self::Input) -> Self {
None
}
}
#[cfg(feature = "alloc")]
impl<T> WithCapacity for Vec<T> {
type Input = usize;
#[inline]
fn with_capacity(input: Self::Input) -> Self {
Vec::with_capacity(input)
}
}
#[cfg(feature = "with-arrayvec")]
impl<A> WithCapacity for arrayvec::ArrayVec<A>
where
A: arrayvec::Array,
{
type Input = usize;
#[inline]
fn with_capacity(_: Self::Input) -> Self {
arrayvec::ArrayVec::new()
}
}
#[cfg(feature = "with-smallvec")]
impl<A> WithCapacity for smallvec::SmallVec<A>
where
A: smallvec::Array,
{
type Input = usize;
#[inline]
fn with_capacity(input: Self::Input) -> Self {
smallvec::SmallVec::with_capacity(input)
}
}
#[cfg(feature = "with-staticvec")]
impl<T, const N: usize> WithCapacity for staticvec::StaticVec<T, N> {
type Input = usize;
#[inline]
fn with_capacity(_: Self::Input) -> Self {
staticvec::StaticVec::new()
}
}
#[cfg(feature = "with-tinyvec")]
impl<A> WithCapacity for tinyvec::ArrayVec<A>
where
A: Default + tinyvec::Array,
A::Item: Default,
{
type Input = usize;
#[inline]
fn with_capacity(_: Self::Input) -> Self {
tinyvec::ArrayVec::new()
}
}
#[cfg(all(feature = "alloc", feature = "with-tinyvec"))]
impl<A> WithCapacity for tinyvec::TinyVec<A>
where
A: Default + tinyvec::Array,
A::Item: Default,
{
type Input = usize;
#[inline]
fn with_capacity(_: Self::Input) -> Self {
tinyvec::TinyVec::new()
}
}