-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
For reference here is the trait EntityCommand
:
pub trait EntityCommand<Out = ()>: Send + 'static {
fn apply(self, entity: EntityWorldMut) -> Out;
}
The method consumes the EntityWorldMut
it takes. I thought an implementation of the trait with Out
as EntityWorldMut
should be able to return its owned argument so I could continue using it afterwards. In its simplest form that would be
struct MyEntityCommand;
impl EntityCommand<EntityWorldMut<'_>> for MyEntityCommand {
fn apply(self, entity: EntityWorldMut) -> EntityWorldMut {
entity
}
}
but this doesn't compile. The compiler complains that the lifetimes of the method argument and its return must be different per the trait signature. I've tried
struct MyEntityCommand;
impl<'a> EntityCommand<EntityWorldMut<'a>> for MyEntityCommand {
fn apply<'b: 'a>(self, entity: EntityWorldMut<'b>) -> EntityWorldMut<'a> {
entity
}
}
Here the compiler complains that b is early bound whereas according to the trait signature it should be late bound. Lifting b at the impl level and the method argument may not live as long.
After research I found this post which seems to solve this exact problem. As suggested I've tried lifting the lifetime to the trait to add the feature in Bevy but I've run into many compiler complaints that I am unable to solve for now. I was wondering if I'm on the right track or if I've missed something.