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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use crate::{Array, ArrayWrapper};

/// Has some sort of storage that holds a maximum number of elements.
pub trait Capacity {
  /// Output type for the [`capacity`](Capacity::capacity)` method.
  type Output;

  /// The number of elements that can be holded.
  fn capacity(&self) -> Self::Output;
}

impl<A> Capacity for ArrayWrapper<A>
where
  A: Array,
{
  type Output = usize;

  fn capacity(&self) -> Self::Output {
    A::CAPACITY
  }
}

#[cfg(feature = "alloc")]
impl<T> Capacity for alloc::vec::Vec<T> {
  type Output = usize;

  fn capacity(&self) -> Self::Output {
    self.capacity()
  }
}

#[cfg(feature = "with_arrayvec")]
impl<A> Capacity for arrayvec::ArrayVec<ArrayWrapper<A>>
where
  A: Array,
{
  type Output = usize;

  fn capacity(&self) -> Self::Output {
    self.capacity()
  }
}

#[cfg(feature = "with_smallvec")]
impl<A> Capacity for smallvec::SmallVec<ArrayWrapper<A>>
where
  A: Array,
{
  type Output = usize;

  fn capacity(&self) -> Self::Output {
    self.capacity()
  }
}

#[cfg(feature = "with_staticvec")]
impl<T, const N: usize> Capacity for staticvec::StaticVec<T, N> {
  type Output = usize;

  fn capacity(&self) -> Self::Output {
    self.capacity()
  }
}