Hi!
I've been trying to find an answer as to why this does not work, but I'm not sure I understand.
pub trait Notifiable {
type EventType;
fn notify(&self, event: Self::EventType);
}
pub trait Observable {
type EventType;
type NotifiableType: Notifiable<EventType = Self::EventType>;
fn observe(&mut self, viewer: Self::NotifiableType);
}
/// Events a window can broadcast to listeners.
pub enum Event {
Generic,
}
pub struct Window {}
impl Observable for Window {
type EventType = Event;
type NotifiableType = Box<dyn Notifiable<EventType = Self::EventType>>;
fn observe(&mut self, viewer: Self::NotifiableType) {
todo!()
}
}
If I don't specify the bounds for Observable::NotifiableType, it does work:
pub trait Observable {
type EventType;
type NotifiableType;
fn observe(&mut self, viewer: Self::NotifiableType);
}
I feel like having the notifiable type be bound to the notifiable trait to be a sane choice, but obviously it does not work. I only get the error:
"the trait bound `Box<(dyn Notifiable<EventType = Event> + 'static)>: Notifiable` is not satisfied
the trait `Notifiable` is not implemented for `Box<(dyn Notifiable<EventType = Event> + 'static)>`"