From 2eade86cf7a12a6ec64496aedbfc3d3a3bd44e1a Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 23 Oct 2022 16:51:49 -0500 Subject: make `handle` cleaner Arc -> Event, Arc> -> State Items in State now need to have interior mutability (i.e. Arc>), but it's a worthwhile tradeoff since it allows the user to customize it for each field --- azalea/examples/echo.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'azalea/examples/echo.rs') diff --git a/azalea/examples/echo.rs b/azalea/examples/echo.rs index a5280d8b..07dd50c1 100644 --- a/azalea/examples/echo.rs +++ b/azalea/examples/echo.rs @@ -12,7 +12,7 @@ async fn main() { azalea::start(azalea::Options { account, address: "localhost", - state: Arc::new(Mutex::new(State::default())), + state: State::default(), plugins: vec![], handle, }) @@ -20,19 +20,16 @@ async fn main() { .unwrap(); } +#[derive(Default, Clone)] pub struct State {} -async fn handle(bot: Client, event: Arc, state: Arc>) -> anyhow::Result<()> { - match *event { +async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> { + match event { Event::Chat(m) => { if m.username == bot.username { return Ok(()); // ignore our own messages }; - bot.chat(m.message).await; - } - Event::Kick(m) => { - println!(m); - bot.reconnect().await.unwrap(); + bot.chat(m.content).await; } _ => {} } -- cgit v1.2.3