rj00a / evenio

An event-driven Entity Component System
MIT License
137 stars 14 forks source link

Fix `#[derive(Event)]` on generic types with type params. #67

Closed rj00a closed 5 months ago

rj00a commented 5 months ago

This PR allows the following code to compile.

#[derive(GlobalEvent)]
struct StructWithGenericType<T>(T);

The problem is the This<'a> associated type requires T to outlive 'a, but there's no way to actually specify that in the impl. As a fix, we add 'static bounds to all generic params.

AFAICT this isn't truly fixable unless Rust adds higher-kinded polymorphism, which isn't happening any time soon. Alternatively, Rust could remove the 'static requirement from TypeId::of which would let us delete This.