[−][src]Macro automate::methods
methods!() { /* proc-macro */ }
Parses a list of method listeners in the initialize method of a state struct.
Input should be the name of the struct followed by a colon and a comma-separated list of the listener functions that should be registered.
use automate::{methods, listener, Context, Error}; use automate::events::{Initializable, StatefulListener}; use automate::gateway::MessageCreateDispatch; struct MessageCounter; impl Initializable for MessageCounter { fn initialize() -> Vec<StatefulListener<Self>> { methods!(MessageCounter: say_hello, say_bye) } } impl MessageCounter { #[listener] async fn say_hello(&mut self, ctx: &Context, data: &MessageCreateDispatch) -> Result<(), Error> { println!("Hello!"); Ok(()) } #[listener] async fn say_bye(&mut self, ctx: &Context, data: &MessageCreateDispatch) -> Result<(), Error> { println!("Bye"); Ok(()) } }