Lokathor / tinyvec

Just, really the littlest Vec you could need. So smol.
https://docs.rs/tinyvec
Apache License 2.0
648 stars 49 forks source link

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

Open Andrepuel opened 1 year ago

Andrepuel commented 1 year ago

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 }
  }
}