tinyvec icon indicating copy to clipboard operation
tinyvec copied to clipboard

Suggestion: const fn to create an ArrayVec with the len, capping if it exceeds the maximum

Open Andrepuel opened this issue 2 years ago • 0 comments

I think it is easier to explain using code:

impl<A: Array> ArrayVec<A> {
  #[inline]
  #[must_use]
  pub const fn from_array_len_capped(data: A, len: u16) -> Self{
    let len = if len as usize <= A::CAPACITY {
      len
    } else {
      A::CAPACITY as u16
    };
    Self { data, len: len as u16 }
  }
}

Andrepuel avatar May 11 '23 22:05 Andrepuel