Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to convert a SmallVec<A> into an A? #85

Closed
sunshowers opened this issue Mar 15, 2018 · 2 comments
Closed

Is there a way to convert a SmallVec<A> into an A? #85

sunshowers opened this issue Mar 15, 2018 · 2 comments

Comments

@sunshowers
Copy link

@sunshowers sunshowers commented Mar 15, 2018

I have need for a variable-length array that is almost always exactly length 32 -- so I'd like to represent it as a SmallVec<[T; 32]>. I'd like to convert it to a [T; 32] without copying. It would be cool to add a method that can try doing the conversion if possible and returns the original SmallVec if it didn't work out:

fn into_array(self) -> Result<A, Self>

What do you think?

@mbrubeck
Copy link
Contributor

@mbrubeck mbrubeck commented Mar 22, 2018

For comparison, arrayvec has an into_inner method for this. It seems reasonable to provide the same feature for smallvec.

Note that this may not be any faster than copying, since it still needs to move the inner array in order to return it, and a move involves a memcpy.

@1tgr 1tgr mentioned this issue Aug 11, 2018
bors-servo added a commit that referenced this issue Aug 13, 2018
Add into_inner

Converts a SmallVec into an array, provided the SmallVec has not been spilled to the heap.

Addresses #85.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-smallvec/115)
<!-- Reviewable:end -->
@mbrubeck
Copy link
Contributor

@mbrubeck mbrubeck commented Aug 13, 2018

Fixed by #115.

@mbrubeck mbrubeck closed this Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.