hannesmann / keyframe

A simple library for animation in Rust
MIT License
130 stars 11 forks source link

Consider adding a `smallvec` feature #10

Closed Type1J closed 2 years ago

Type1J commented 3 years ago

Vec is explicitly given attention in this crate, but smallvec may be a better fit for most use cases of this library, and may allow (through return value optimization) the use of this crate with a Vec-like type without allocation.

hannesmann commented 3 years ago

I've been busy so I'll look at this issue and #9 later. :slightly_smiling_face:

Really I don't think Vec is even the right choice for what keyframe is trying to do. What I wanted was a generic version of mint::Vector2<T>, mint::Vector3<T>, etc. so you could tween between two arrays of the same size where all the elements are the same type. Ideally this would be checked at compile time and implemented with a generic array type ([T; N]) but as far as I know Rust still doesn't support generic arrays, so I went with Vec<T> and a runtime check for mismatched size.

Type1J commented 3 years ago

I believe that Rust 1.51 added that feature.

niclashoyer commented 2 years ago

Yes, this feature is called const generics. I'm considering to use this crate in a no_std environment to implement visual effects. It would be great if it was possible to use the keyframe module in no_std, too.

If you still need a Vec for something, please also consider heapless::Vec which also uses const generics for a fixed allocation with Vec semantics.