#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::vec::Vec;
pub trait Push {
type Input;
type Output;
fn push(&mut self, input: Self::Input) -> Self::Output;
}
impl<T> Push for Option<T> {
type Input = T;
type Output = ();
#[inline]
fn push(&mut self, input: Self::Input) {
if self.is_some() {
panic!("Exceeded capacity for Option");
} else {
*self = Some(input);
}
}
}
#[cfg(feature = "alloc")]
impl<T> Push for Vec<T> {
type Input = T;
type Output = ();
#[inline]
fn push(&mut self, input: Self::Input) {
self.push(input)
}
}
#[cfg(feature = "with-arrayvec")]
impl<A> Push for arrayvec::ArrayVec<A>
where
A: arrayvec::Array,
{
type Input = A::Item;
type Output = ();
#[inline]
fn push(&mut self, input: Self::Input) {
self.push(input)
}
}
#[cfg(feature = "with-smallvec")]
impl<A> Push for smallvec::SmallVec<A>
where
A: smallvec::Array,
{
type Input = A::Item;
type Output = ();
#[inline]
fn push(&mut self, input: Self::Input) {
self.push(input)
}
}
#[cfg(feature = "with-staticvec")]
impl<T, const N: usize> Push for staticvec::StaticVec<T, N> {
type Input = T;
type Output = ();
#[inline]
fn push(&mut self, input: Self::Input) {
self.push(input)
}
}
#[cfg(feature = "with-tinyvec")]
impl<A> Push for tinyvec::ArrayVec<A>
where
A: tinyvec::Array,
A::Item: Default,
{
type Input = A::Item;
type Output = ();
#[inline]
fn push(&mut self, input: Self::Input) {
self.push(input)
}
}
#[cfg(all(feature = "alloc", feature = "with-tinyvec"))]
impl<A> Push for tinyvec::TinyVec<A>
where
A: tinyvec::Array,
A::Item: Default,
{
type Input = A::Item;
type Output = ();
#[inline]
fn push(&mut self, input: Self::Input) {
self.push(input)
}
}