legion icon indicating copy to clipboard operation
legion copied to clipboard

Request: Remove Copy bound from Components

Open HindrikStegenga opened this issue 5 years ago • 3 comments

I came across this project and tried to use it in my engine, however, components seem to need the copy bound, which is unfortunate. Is there any good reason why this is necessary? Wouldn't clone suffice?

HindrikStegenga avatar Jan 17 '20 09:01 HindrikStegenga

Component is defined as:

pub trait Component: Send + Sync + 'static {}

And it is implemented automatically on all such types. Can you provide an example of an error you might be getting when trying to use a non-Copy type as a component? There may be an issue somewhere with some of our other types or macro implementations which could be causing this.

TomGillen avatar Jan 18 '20 16:01 TomGillen

@TomGillen Filter types require T: to be copy, so a filter cant be constructed for any type because of this.

It looks like that requirement exists beacuse of the recursive_zip usage on impl_filter_or, which performs component-wise copies for comparisons it seems like?

I believe these filters could be re-worked to remove that.

jaynus avatar Jan 18 '20 21:01 jaynus

I looked at the various implementations of Filter<T>::collect and noticed that none of them consumed their argument (which makes sense given until now they have all required T: Copy) so I switched it to take &T to see if anything broke. All the test pass and it compiles but I don't know if it is the best solution. https://github.com/Guvante/legion/commit/148bbde9fe724536bc0c6c01c6718fb1e106edcd has that in case anyone is curious how it looks.

I thought a bit about how to be able to just say Filter<&T> instead if the type isn't Copy but that feels like a way to get trapped by overlapping instances pretty quickly. Also swapping all the Component stuff to use Filter<&T> felt like the same as this fix.

Guvante avatar Jan 19 '20 22:01 Guvante