Open lopopolo opened 3 years ago
Hi :wave:
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.
Array
Vec
SmallVec
TinyVec
PR is here: https://github.com/artichoke/artichoke/pull/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 -- https://github.com/artichoke/artichoke/commit/1935c0543a9c26176494377da8c351a66a181eca.
T: Default
I appreciated the increased API compatibility with Vec compared to SmallVec, in particular a splice method, which let me simplify several methods.
splice
There were two things I was missing:
vec!
SmallVec::from_elem
iter::repeat
Self(iter::repeat(default).take(len).collect())
From<Vec<T>>
vec::IntoIter
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.
Hi :wave:
I maintain a crate that abstracts over growable vectors such that they would be appropriate for implementing a Ruby
Array
. This crate had backends forVec
andSmallVec
. Yesterday I added a backend forTinyVec
.PR is here: https://github.com/artichoke/artichoke/pull/1094.
I based the
TinyVec
backend on the existing backend forSmallVec
. Apart from adding a boatload ofT: Default
bounds, the change was actually really small -- https://github.com/artichoke/artichoke/commit/1935c0543a9c26176494377da8c351a66a181eca.I appreciated the increased API compatibility with
Vec
compared toSmallVec
, in particular asplice
method, which let me simplify several methods.There were two things I was missing:
vec!
orSmallVec::from_elem
with a non-constant length. I had to useiter::repeat
like this:From<Vec<T>>
impl, which forces one to go throughvec::IntoIter
even if theTinyVec
would be spilled with thisVec
.