From 87726617725e4f95c53b3bc8a573553b04c57563 Mon Sep 17 00:00:00 2001 From: mat Date: Mon, 23 Dec 2024 10:34:44 +0000 Subject: lift requirement on anyhow for handler function --- azalea/src/lib.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'azalea/src/lib.rs') diff --git a/azalea/src/lib.rs b/azalea/src/lib.rs index 5e412f52..e8a85101 100644 --- a/azalea/src/lib.rs +++ b/azalea/src/lib.rs @@ -44,8 +44,7 @@ use protocol::{resolver::ResolverError, ServerAddress}; use swarm::SwarmBuilder; use thiserror::Error; -pub type BoxHandleFn = - Box BoxFuture<'static, Result<(), anyhow::Error>>>; +pub type BoxHandleFn = Box BoxFuture<'static, R>>; pub type HandleFn = fn(Client, azalea_client::Event, S) -> Fut; #[derive(Error, Debug)] @@ -74,19 +73,20 @@ pub enum StartError { /// # Ok(()) /// # } /// ``` -pub struct ClientBuilder +pub struct ClientBuilder where S: Default + Send + Sync + Clone + Component + 'static, + R: Send + 'static, { /// Internally, ClientBuilder is just a wrapper over SwarmBuilder since it's /// technically just a subset of it so we can avoid duplicating code this /// way. - swarm: SwarmBuilder, + swarm: SwarmBuilder, } -impl ClientBuilder { +impl ClientBuilder { /// Start building a client that can join the world. #[must_use] - pub fn new() -> ClientBuilder { + pub fn new() -> Self { Self::new_without_plugins() .add_plugins(DefaultPlugins) .add_plugins(DefaultBotPlugins) @@ -116,7 +116,7 @@ impl ClientBuilder { /// # } /// ``` #[must_use] - pub fn new_without_plugins() -> ClientBuilder { + pub fn new_without_plugins() -> Self { Self { swarm: SwarmBuilder::new_without_plugins(), } @@ -139,19 +139,21 @@ impl ClientBuilder { /// } /// ``` #[must_use] - pub fn set_handler(self, handler: HandleFn) -> ClientBuilder + pub fn set_handler(self, handler: HandleFn) -> ClientBuilder where S: Default + Send + Sync + Clone + Component + 'static, - Fut: Future> + Send + 'static, + Fut: Future + Send + 'static, + R: Send + 'static, { ClientBuilder { swarm: self.swarm.set_handler(handler), } } } -impl ClientBuilder +impl ClientBuilder where S: Default + Send + Sync + Clone + Component + 'static, + R: Send + 'static, { /// Set the client state instead of initializing defaults. #[must_use] @@ -206,7 +208,7 @@ where self.swarm.start_with_default_opts(address, opts).await } } -impl Default for ClientBuilder { +impl Default for ClientBuilder { fn default() -> Self { Self::new() } -- cgit v1.2.3