tinyvec
tinyvec copied to clipboard
Suggestion: const fn to create an ArrayVec with the len, capping if it exceeds the maximum
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 }
}
}