Merge pull request 'Use generic parameter instead of boxing to allow mutable handlers' (#1) from imp-fixes into main

Reviewed-on: #1
This commit is contained in:
Dan Ballard 2022-04-26 21:30:42 +00:00
commit d61c4086d4
1 changed files with 2 additions and 2 deletions

View File

@ -75,7 +75,7 @@ impl BehaviourBuilder {
/// Trait to be used by implementors of imp bots to supply their custom event handling
/// the handle function is called after the default imp automatic event handling has run on each new event
pub trait EventHandler {
fn handle(&self, cwtch: &dyn CwtchLib, profile: Option<&Profile>, event: CwtchEvent);
fn handle(&mut self, cwtch: &dyn CwtchLib, profile: Option<&Profile>, event: CwtchEvent);
}
/// Cwtch bot
@ -102,7 +102,7 @@ impl Imp {
}
/// The main event loop handler for the bot, supply your own customer handler to handle events after the imp's automatic handling has processed the event
pub fn event_loop(&mut self, handler: Box<dyn EventHandler>) {
pub fn event_loop<T>(&mut self, handler: &mut T) where T : EventHandler {
let mut initialized: bool = false;
loop {