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

From<Vec<T>> impl for TinyVec #135

Open
lopopolo opened this issue Feb 16, 2021 · 1 comment
Open

From<Vec<T>> impl for TinyVec #135

lopopolo opened this issue Feb 16, 2021 · 1 comment
Labels
Enhancement New feature or request

Comments

@lopopolo
Copy link

lopopolo commented Feb 16, 2021

Hi 👋

I maintain a crate that abstracts over growable vectors such that they would be appropriate for implementing a Ruby Array. This crate had backends for Vec and SmallVec. Yesterday I added a backend for TinyVec.

PR is here: artichoke/artichoke#1094.

I based the TinyVec backend on the existing backend for SmallVec. Apart from adding a boatload of T: Default bounds, the change was actually really small -- artichoke/artichoke@1935c05.

I appreciated the increased API compatibility with Vec compared to SmallVec, in particular a splice method, which let me simplify several methods.

There were two things I was missing:

  • There is no equivalent of vec! or SmallVec::from_elem with a non-constant length. I had to use iter::repeat like this:
    Self(iter::repeat(default).take(len).collect())
  • There is no From<Vec<T>> impl, which forces one to go through vec::IntoIter even if the TinyVec would be spilled with this Vec.
@Lokathor Lokathor added the Enhancement New feature or request label Feb 16, 2021
@Lokathor
Copy link
Owner

Those both sound useful.

The impl sounds easy, but the macro one might be harder to slot in because we've already got quite a few macro arms, but you could probably fit it in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants