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