I am currently learning Rust by making a dummy ECS, given the following function:
pub fn add_component<T: Component + 'static>(&mut self, component: T) {
let type_id = TypeId::of::<T>();
}
I won’t compile without 'static
–
I don’t understand why, since I am taking ownership of component
– why is Rust worried about this component getting de-allocated.
the parameter type `T` may not live long enough
the parameter type `T` must be valid for the static lifetime
As long as it exists within the function scope (which it does) it should be good.
EDIT:
Component is defined as:
trait Component {
fn update(&self);
fn render(&self);
}