Open aji opened 9 years ago
My immediate response to this is to a field tocore::Bot
to store handlers (a HashMap<Vec<u8>, Vec<Handler>>
?) and provide some kind of interface to let other modules add (and remove?) them. And the last requirement seems pretty easy; Handler
s could have Fn
s that take mutable references to the EventedCtl
and Reactor
.
yeah, passing a mutable reference to the EventedCtl
is possible, but only because Bot
has both &mut self
and &mut EventedCtl
as arguments to on_line
. the sneaky problem with this (and part of why EventedCtl
etc. exists) is because when one struct is inside of another, you can't pass mutable references to both without upsetting the borrow checker. that's why Bot
is not inside of EventedCtl
, and vice versa.
…hmm, the Reactor
is local to Bot::run()
. I think that's gonna have to change if we want to lend it to handlers…could we make it a Bot
field, too?
this is blocking all the interesting work, so I'll try to get to it this weekend
this is sort of handled in the nonsense here now https://github.com/aji/miau/blob/master/src/network.rs#L110-L142
miles ahead of what we had before
Right now a single
match
is used, which is good enough for the moment. However, a more robust framework for registering IRC command handlers should be implemented.For the framework to be considered complete, it must meet the following requirements:
Evented
the message arrived on, and alter the globalReactor
. TheEvented
portion of this should seem obvious, but the event loop part is a bit more subtle. We may want to spawn or close a connection while in a message handler, so it's important to be able to alter theReactor
as well.