#[cfg(feature = "alloc")]
use alloc::{string::String, 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) -> Self::Output {
if input == 0 {
*self = None;
}
}
}
#[cfg(feature = "alloc")]
impl Truncate for String {
type Input = usize;
type Output = ();
#[inline]
fn truncate(&mut self, input: Self::Input) -> Self::Output {
self.truncate(input);
}
}
#[cfg(feature = "alloc")]
impl<T> Truncate for Vec<T> {
type Input = usize;
type Output = ();
#[inline]
fn truncate(&mut self, input: Self::Input) -> Self::Output {
self.truncate(input);
}
}
#[cfg(feature = "arrayvec")]
impl<const N: usize> Truncate for arrayvec::ArrayString<N> {
type Input = usize;
type Output = ();
#[inline]
fn truncate(&mut self, input: Self::Input) -> Self::Output {
self.truncate(input);
}
}
#[cfg(feature = "arrayvec")]
impl<T, const N: usize> Truncate for arrayvec::ArrayVec<T, N> {
type Input = usize;
type Output = ();
#[inline]
fn truncate(&mut self, input: Self::Input) -> Self::Output {
self.truncate(input);
}
}
#[cfg(feature = "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::Output {
self.truncate(input);
}
}
#[cfg(feature = "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::Output {
self.truncate(input);
}
}
#[cfg(feature = "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::Output {
self.truncate(input);
}
}
#[cfg(feature = "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::Output {
self.truncate(input);
}
}