Lokathor / tinyvec

Just, really the littlest Vec you could need. So smol.
https://docs.rs/tinyvec
Apache License 2.0
648 stars 49 forks source link

TinyVec/ArrayVec's `Clone` uses the naive (default) version of Clone::clone_from. #143

Closed thomcc closed 3 years ago

thomcc commented 3 years ago

You derive Clone on TinyVec/ArrayVec. This means you get the default impl of clone_from, which doesn't allow items stored inside these to reuse their memory. (Ideally, #[derive(Clone)] would do this, but they don't, as it would increase compile time for all rust programs for a rarely-used method. Thankfully, at least all the stdlib container provide impls of this...)

I'm using this for a TinyVec<[FloatImagePlane; 4]> (a float image plane being a Vec<f32> and some metadata). These cane be fairly large, so I'd have an option to have the memory reused.

I think this implementation that should work. I didn't write tests, and don't have time to PR it. https://gist.github.com/thomcc/56f9804d23459da4650112a573acf9dd.