Skip to content

Add From<SmallVec> implementations for Vec and Box<[T]> - #649

Merged
alejandro-vaz merged 1 commit into
servo:v2from
shuaixr:feat/from-smallvec-for-vec-box
Sep 24, 2026
Merged

alejandro-vaz merged 1 commit into
servo:v2from
shuaixr:feat/from-smallvec-for-vec-box

Conversation

@shuaixr

@shuaixr shuaixr commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #633
Implemented the From trait for converting SmallVec into Vec and Box<[T]> using the existing into methods, and added tests for both.

feedback and suggestions are welcome!

@shuaixr
shuaixr marked this pull request as ready for review September 21, 2026 00:28
@alejandro-vaz
alejandro-vaz self-requested a review September 21, 2026 09:33

@alejandro-vaz alejandro-vaz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@shuaixr

shuaixr commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

Oh yes, I overlooked that.
I can update the implementation once #632 is resolved.

@alejandro-vaz

Copy link
Copy Markdown
Collaborator

I'm making the PR as a draft since it is blocked

to have it mentally checked in

@alejandro-vaz
alejandro-vaz marked this pull request as draft September 21, 2026 13:53
@alejandro-vaz

Copy link
Copy Markdown
Collaborator

okay all fuzzing and new CI and allocator features have landed

we finally agreed on something simpler: all the conversions that use Vec and Box will use crate::Vec and crate::Box that come from our custom allocator backend

that means, by default and with the feature allocator-api it uses alloc::{vec::Vec, boxed::Box}, and with the feature allocator-api2 it uses allocator_api2::{vec::Vec, boxed::Box}

can you update with this??

@alejandro-vaz
alejandro-vaz marked this pull request as ready for review September 24, 2026 11:57
@alejandro-vaz alejandro-vaz linked an issue Sep 24, 2026 that may be closed by this pull request
@shuaixr
shuaixr force-pushed the feat/from-smallvec-for-vec-box branch from fe5a2b2 to 1d26666 Compare September 24, 2026 14:35
@shuaixr

shuaixr commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

Yeah, I’ve updated it. Please take a look

@shuaixr
shuaixr force-pushed the feat/from-smallvec-for-vec-box branch from 1d26666 to c8d1704 Compare September 24, 2026 14:43
Comment thread tests/main.rs Outdated
Comment on lines +855 to +876
#[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]);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are these tests necessary??

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we have similar ones??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes they a bit redundant. I’ll remove it

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm planning to deprecate the into_* methods soon so naturally the other tests will migrate to use Into::into anyway

@shuaixr
shuaixr force-pushed the feat/from-smallvec-for-vec-box branch from c8d1704 to cad7b40 Compare September 24, 2026 14:51
@alejandro-vaz

Copy link
Copy Markdown
Collaborator

thanks for contributing @shuaixr

@alejandro-vaz
alejandro-vaz added this pull request to the merge queue Sep 24, 2026
Merged via the queue into servo:v2 with commit b33362e Sep 24, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add missing From conversions to SmallVec fix allocator API into_boxed_slice and into_vec

2 participants