arrayvec
arrayvec copied to clipboard
Add `From<[T; LEN]>`
We can use compile-time assert
s to check that LEN <= CAP
, and then only initialize the first LEN
elements. So something like
impl<T, const LEN: usize, const CAP: usize> From<[T; LEN]> for ArrayVec<T, CAP> {
fn from(arr: [T; LEN]) -> Self {
assert!(LEN <= CAP);
// duplicate the rest of From<[T; LEN]> for ArrayVec<T, LEN> here
}
}
I think, we should wait with this until trait bounds would be available so we can write something like this:
impl<T, const LEN: usize, const CAP: usize> From<[T; LEN]> for ArrayVec<T, CAP>
where LEN <= CAP
{
fn from(arr: [T; LEN]) -> Self {
// duplicate the rest of From<[T; LEN]> for ArrayVec<T, LEN> here
}
}