1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
#[cfg(feature = "smallvec")]
use smallvec::{Array as SmallVecArray, SmallVec};

/// Has some way to truncate some sort of storage.
pub trait Truncate {
  /// Input type for the [`truncate`](Truncate::truncate)` method.
  type TruncateInput;
  /// Return type for the [`truncate`](Truncate::truncate)` method.
  type TruncateRet;

  /// Truncates the storage.
  fn truncate(&mut self, input: Self::TruncateInput) -> Self::TruncateRet;
}

#[cfg(feature = "smallvec")]
impl<A> Truncate for SmallVec<A>
where
  A: SmallVecArray,
{
  type TruncateInput = usize;
  type TruncateRet = ();

  fn truncate(&mut self, input: Self::TruncateInput) {
    self.truncate(input)
  }
}

#[cfg(feature = "alloc")]
impl<T> Truncate for Vec<T> {
  type TruncateInput = usize;
  type TruncateRet = ();

  fn truncate(&mut self, input: Self::TruncateInput) {
    self.truncate(input)
  }
}