hannesmann / keyframe

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

Why must `Keyframe<T>.value()` be `T: Copy`? #15

Open TheButlah opened 2 years ago

TheButlah commented 2 years ago

Why must T be Copy? How can one access a value in a keyframe with non-copy types?

TheButlah commented 2 years ago

I believe the motivation here must be to avoid unnecessary allocations. This makes sense as allocating on each tween would be crippling for performance.

Perhaps instead of returning an owned type, the caller to ease() could pass an output: &mut Self? That would allow for tweening types that are non-copy, by writing into the output.

hannesmann commented 2 years ago

I believe the reason for ease() working with values rather than references is that the former is better for primitive types. An f32 is smaller than a pointer on 64-bit processors, and it should be slightly faster since no dereferencing is needed.

Tweening primitive values or small structures seemed like the most common use case to me at the time, but the current design obviously has some downsides for larger structures or structures that can't be copied.