diff options
| author | mat <github@matdoes.dev> | 2022-10-23 16:51:49 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-10-23 16:51:49 -0500 |
| commit | 2eade86cf7a12a6ec64496aedbfc3d3a3bd44e1a (patch) | |
| tree | c010d3f02beaec29741b723a1bc6e7eaad59e193 /bot | |
| parent | a9ff79a10553026b0fa32f0e31f1e0442467ca78 (diff) | |
| download | azalea-drasl-2eade86cf7a12a6ec64496aedbfc3d3a3bd44e1a.tar.xz | |
make `handle` cleaner
Arc<Event> -> Event, Arc<Mutex<State>> -> State
Items in State now need to have interior mutability (i.e. Arc<Mutex<T>>), but it's a worthwhile tradeoff since it allows the user to customize it for each field
Diffstat (limited to 'bot')
| -rw-r--r-- | bot/src/main.rs | 10 |
1 files changed, 4 insertions, 6 deletions
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<Event>, _state: Arc<Mutex<State>>) -> anyhow::Result<()> { - match *event { +async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()> { + match event { Event::Login => { bot.chat("Hello world").await?; } |
