pub use crate::dispatcher::*; use crate::messages::prelude::*; /// Implements a message handler struct for a separate message struct. /// - The first generic argument (`M`) is that message struct type, representing a message enum variant to be matched and handled in `process_message()`. /// - The second generic argument (`D`) is the type of data that can be passed along by the caller to `process_message()`. pub trait MessageHandler where M::Discriminant: AsMessage, ::TopParent: TransitiveChild::TopParent, TopParent = ::TopParent> + AsMessage, { /// Return true if the Action is consumed. fn process_message(&mut self, message: M, responses: &mut VecDeque, data: D); fn actions(&self) -> ActionList; } pub type ActionList = Vec>; pub trait AsMessage: TransitiveChild where Self::TopParent: TransitiveChild + AsMessage, { fn local_name(self) -> String; fn global_name(self) -> String { >::into(self).local_name() } } // TODO: Add Send + Sync requirement // Use something like rw locks for synchronization pub trait MessageHandlerData {} pub trait ToDiscriminant { type Discriminant; fn to_discriminant(&self) -> Self::Discriminant; } pub trait TransitiveChild: Into + Into { type TopParent; type Parent; } pub trait Hint { fn hints(&self) -> HashMap; }