Closed sunjay closed 5 years ago
This is a good change and an issue with the original implementation that I was uneasy about at the time. Thanks for fixing it. I'll release 0.3
to coincide with these changes.
All that needs to happen is for the conflicts to be resolved.
@zesterer Done! Thank you for reviewing my changes and publishing that release. :smile:
@sunjay Feel free to add your name to the author list!
@zesterer I'll do that in the next PR (someday) :smile: Thanks for merging my PRs! Looking forward to 0.3
. :tada:
@sunjay 0.3
was just published!
Awesome! Thank you! :tada: :tada: :tada:
I ran into a problem today and this PR aims to help address that.
I actually noticed that the documentation for
get()
in theTarget
trait in some ways reflects the change I'm currently proposing: (emphasis mine)It says "copy", but the
get()
method currently returns a reference. Furthermore, if you search forget()
in the repo, all its usages are immediately dereferenced. That means that we could potentially just return a clone and remove those dereferences.This PR changes the
get()
method in theTarget
trait to returnSelf::Item
instead of&Self::Item
. It then makes any related changes to other parts of the code.Use Case
The reason I'm suggesting this is because I actually ran into a situation today where I really need this trait to return
Self::Item
instead of a reference.The problem I have is in some FFI code. I have some shared memory represented as
Vec<u8>
and I use aeuc::Pipeline
implementation that returnsvek::Rgba<f32>
. TheVec<u8>
is laid out in quadruples of (r, g, b, a).Rather than maintaining a separate
Buffer2d<Rgba<f32>>
, I want to avoid copying and just use theVec<u8>
directly. I can implementset()
very easily, but implementingget()
is impossible because I can't return a&Rgba<f32>
from&[u8]
. I can however returnRgba<f32>
.The changes in this PR would make
euc
usable for me in this case.Impact of this change
I think the clone has minimal cost in almost all circumstances and will probably be optimized away. The only time
get()
is used in the various rasterizers is for the depth buffer anyway. That almost always has typeBuffer2d<f32>
and cloning anf32
should be very cheap.This would be a breaking change, so
0.3
would need to be released, but hopefully that is no big deal.If you decide to merge this PR and my other one (#2) with no changes required, could you please release a new 0.3 of euc? Thank you :)