So, I'm trying to compress callbacks to this enumeration ( Visual) option - which will be saved in a vector, as shown inside a struct EntityComponents:
enum Component {
Position([f64; 2]),
Visual(& Fn(Entity) -> ()),
}
struct EntityComponents {
components_of_entity: HashMap<TypeId, Vec<Component>>,
}
However, Rust requires me to provide explicit lifetime parameters here. My idea is that I want the function reference to be at least as long as its argument ( Entity), but I don't know what the syntax for this will look like? Is it possible?
The idea is that as long as it Entityhas a component Visual, we can use this callback to display it!
source
share