Hi! I’m trying to understand how to code events and listeners but I’m new
Expressed in C++ land, I would like to have a listener class and an event class.
Listeners are parameterized by K : Event, V. They have a function listen that listens to a message of type V. They should be able to listen to multiple K’s even when the V is the same:
listen(double d) #listens to K1 : Event
listen(double d) #listens to K2 : Event
The event class contains an iterable of listeners. An implementation of the event class has an iterable of listeners where the K is itself and the V can be specified depending on what I as an event communicate.
Here was my attempt at first:
trait Listener<K : Event, V> {
fn listen<K, V>(v : V);
}
struct Event {
l : Vec<Listener<Event, V>>,
}
impl Event {
fn activate_listeners(d : V) {
for n in l {
n.listen(d);
}
}
}
This won’t even compile
Thanks so so much for the help!
James