You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We can use compile-time asserts to check that LEN <= CAP, and then only initialize the first LEN elements. So something like
impl<T,constLEN:usize,constCAP:usize>From<[T;LEN]>forArrayVec<T,CAP>{fnfrom(arr:[T;LEN]) -> Self{assert!(LEN <= CAP);// duplicate the rest of From<[T; LEN]> for ArrayVec<T, LEN> here}}
The text was updated successfully, but these errors were encountered:
khoover
changed the title
Add From<[T; LEN]> where T: Default
Add From<[T; LEN]>Dec 11, 2022
I think, we should wait with this until trait bounds would be available so we can write something like this:
impl<T,constLEN:usize,constCAP:usize>From<[T;LEN]>forArrayVec<T,CAP>whereLEN <= CAP{fnfrom(arr:[T;LEN]) -> Self{// duplicate the rest of From<[T; LEN]> for ArrayVec<T, LEN> here}}
We can use compile-time
assert
s to check thatLEN <= CAP
, and then only initialize the firstLEN
elements. So something likeThe text was updated successfully, but these errors were encountered: