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
64
65
66
67
68
/// Has some sort of storage that holds a certain number of elements.
pub trait Length {
  /// Outputurn type for the [`length`](Length::length)` method.
  type Output;

  /// The number of elements.
  fn length(&self) -> Self::Output;
}

impl<'a, T> Length for &'a [T] {
  type Output = usize;

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

impl<'a, T> Length for &'a mut [T] {
  type Output = usize;

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

impl<T, const N: usize> Length for [T; N] {
  type Output = usize;

  fn length(&self) -> Self::Output {
    N
  }
}

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

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

#[cfg(feature = "with_arrayvec")]
impl<T, const N: usize> Length for arrayvec::ArrayVec<crate::ArrayWrapper<T, N>> {
  type Output = usize;

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

#[cfg(feature = "with_smallvec")]
impl<T, const N: usize> Length for smallvec::SmallVec<crate::ArrayWrapper<T, N>> {
  type Output = usize;

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

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

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