Add From<SmallVec> implementations for Vec and Box<[T]> - #649
Conversation
alejandro-vaz
left a comment
There was a problem hiding this comment.
this PR is blocked by #632
we're still not sure of how to fix it but the logical fix would be to have two box and two vec conversions, one for the normal alloc and the other for the allocator-api supplied box/vec
|
Oh yes, I overlooked that. |
|
I'm making the PR as a draft since it is blocked to have it mentally checked in |
|
okay all fuzzing and new CI and allocator features have landed we finally agreed on something simpler: all the conversions that use that means, by default and with the feature can you update with this?? |
fe5a2b2 to
1d26666
Compare
|
Yeah, I’ve updated it. Please take a look |
1d26666 to
c8d1704
Compare
| #[test] | ||
| fn vec_from_small_vec() { | ||
| let small_vec = SmallVec::<u8, 2>::from_iter(0..2); | ||
| let vec = Vec::from(small_vec); | ||
| assert_eq!(vec, Vec::from([0, 1])); | ||
|
|
||
| let small_vec = SmallVec::<u8, 2>::from_iter(0..3); | ||
| let vec = Vec::from(small_vec); | ||
| assert_eq!(vec, Vec::from([0, 1, 2])); | ||
| } | ||
|
|
||
| #[test] | ||
| fn box_from_small_vec() { | ||
| let small_vec = SmallVec::<u8, 2>::from_iter(0..2); | ||
| let boxed_slice = Box::<[u8]>::from(small_vec); | ||
| assert_eq!(&*boxed_slice, &[0, 1]); | ||
|
|
||
| let small_vec = SmallVec::<u8, 2>::from_iter(0..3); | ||
| let boxed_slice = Box::<[u8]>::from(small_vec); | ||
| assert_eq!(&*boxed_slice, &[0, 1, 2]); | ||
| } | ||
|
|
There was a problem hiding this comment.
why are these tests necessary??
There was a problem hiding this comment.
don't we have similar ones??
There was a problem hiding this comment.
yes they a bit redundant. I’ll remove it
There was a problem hiding this comment.
I'm planning to deprecate the into_* methods soon so naturally the other tests will migrate to use Into::into anyway
c8d1704 to
cad7b40
Compare
|
thanks for contributing @shuaixr |
Closes: #633
Implemented the
Fromtrait for convertingSmallVecintoVecandBox<[T]>using the existingintomethods, and added tests for both.feedback and suggestions are welcome!