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 --- bot/src/main.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'bot') diff --git a/bot/src/main.rs b/bot/src/main.rs index beed4320..9f8bd0c8 100644 --- a/bot/src/main.rs +++ b/bot/src/main.rs @@ -1,9 +1,7 @@ use azalea::prelude::*; use azalea::{Account, Client, Event}; -use parking_lot::Mutex; -use std::sync::Arc; -#[derive(Default)] +#[derive(Default, Clone)] struct State {} #[tokio::main] @@ -15,7 +13,7 @@ async fn main() -> anyhow::Result<()> { azalea::start(azalea::Options { account, address: "localhost", - state: Arc::new(Mutex::new(State::default())), + state: State::default(), plugins: vec![], handle, }) @@ -25,8 +23,8 @@ async fn main() -> anyhow::Result<()> { Ok(()) } -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::Login => { bot.chat("Hello world").await?; } -- cgit v1.2.3