diff options
| author | mat <git@matdoes.dev> | 2026-05-06 18:38:23 -0545 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2026-05-07 08:05:58 -1200 |
| commit | cabc8b60a729ba17f5b75f7a7956c6d1ddcc8919 (patch) | |
| tree | 237fd12a9768fe7431ce42dfbdde60f4c7850e06 /azalea/src | |
| parent | 9ffd0e80bbb3feace231553d6539124585b03e3c (diff) | |
| download | azalea-drasl-cabc8b60a729ba17f5b75f7a7956c6d1ddcc8919.tar.xz | |
azalea-brigadier now allows commands to return a Result
Diffstat (limited to 'azalea/src')
| -rw-r--r-- | azalea/src/_docs/performance.md | 5 | ||||
| -rw-r--r-- | azalea/src/client_impl/mod.rs | 5 | ||||
| -rw-r--r-- | azalea/src/container.rs | 13 | ||||
| -rw-r--r-- | azalea/src/lib.rs | 7 |
4 files changed, 19 insertions, 11 deletions
diff --git a/azalea/src/_docs/performance.md b/azalea/src/_docs/performance.md index bf580f73..d7d2f596 100644 --- a/azalea/src/_docs/performance.md +++ b/azalea/src/_docs/performance.md @@ -91,14 +91,15 @@ If the client doesn't need a high view distance, then you can reduce the number This can be done by having something like the following in your handler function: ```rust,no_run # use azalea::ClientInformation; -# async fn handle(bot: azalea::Client, event: azalea::Event, state: azalea::NoState) { +# async fn handle(bot: azalea::Client, event: azalea::Event, state: azalea::NoState) -> azalea::error::AzaleaResult<()> { # match event { azalea::Event::Init => bot.set_client_information(ClientInformation { view_distance: 2, ..Default::default() -}), +})?, # _ => {} # } +# Ok(()) # } ``` diff --git a/azalea/src/client_impl/mod.rs b/azalea/src/client_impl/mod.rs index ba78fee4..e0718375 100644 --- a/azalea/src/client_impl/mod.rs +++ b/azalea/src/client_impl/mod.rs @@ -355,9 +355,10 @@ impl Client { /// /// ``` /// # use azalea_core::position::ChunkPos; - /// # fn example(client: &azalea::Client) { - /// let world = client.partial_world(); + /// # fn example(client: &azalea::Client) -> azalea::error::AzaleaResult<()> { + /// let world = client.partial_world()?; /// let is_0_0_loaded = world.read().chunks.limited_get(&ChunkPos::new(0, 0)).is_some(); + /// # Ok(()) /// # } pub fn partial_world(&self) -> AzaleaResult<Arc<RwLock<PartialWorld>>> { let world_holder = self.component::<WorldHolder>()?; diff --git a/azalea/src/container.rs b/azalea/src/container.rs index 0a5c8c01..1a8b1721 100644 --- a/azalea/src/container.rs +++ b/azalea/src/container.rs @@ -37,14 +37,14 @@ impl Client { /// /// ``` /// # use azalea::{prelude::*, registry::builtin::BlockKind}; - /// # async fn example(mut bot: azalea::Client) -> AzaleaResult<()> { + /// # async fn example(mut bot: azalea::Client) -> azalea::error::AzaleaResult<()> { /// let target_pos = bot - /// .world() + /// .world()? /// .read() - /// .find_block(bot.position(), &BlockKind::Chest.into()); + /// .find_block(bot.position()?, &BlockKind::Chest.into()); /// let Some(target_pos) = target_pos else { /// bot.chat("no chest found"); - /// return; + /// return Ok(()); /// }; /// let container = bot.open_container_at(target_pos).await?; /// # Ok(()) @@ -256,11 +256,12 @@ impl ContainerHandleRef { /// /// ```no_run /// # use azalea::prelude::*; - /// # fn example(bot: &Client) { - /// let inventory = bot.get_inventory(); + /// # fn example(bot: &Client) -> azalea::error::AzaleaResult<()> { + /// let inventory = bot.get_inventory()?; /// let inventory_title = inventory.title().unwrap_or_default().to_string(); /// // would be true if an unnamed chest is open /// assert_eq!(inventory_title, "Chest"); + /// # Ok(()) /// # } /// ``` pub fn title(&self) -> Option<FormattedText> { diff --git a/azalea/src/lib.rs b/azalea/src/lib.rs index 3a2bc0cf..8c29e2c3 100644 --- a/azalea/src/lib.rs +++ b/azalea/src/lib.rs @@ -66,11 +66,16 @@ use futures::future::BoxFuture; pub use join_opts::JoinOpts; pub use crate::{ - client_impl::{Client, StartClientOpts}, + client_impl::{Client, StartClientOpts, error}, entity_ref::EntityRef, events::Event, }; +// for convenience, adds the alias `azalea::Result` instead of +// `azalea::error::AzaleaResult`. the user should probably be using anyhow/eyre, +// but in some cases they may prefer to have the errors more strictly defined. +pub type Result<T> = error::AzaleaResult<T>; + pub type BoxHandleFn<S, R> = Box<dyn Fn(Client, Event, S) -> BoxFuture<'static, R> + Send>; pub type HandleFn<S, Fut> = fn(Client, Event, S) -> Fut; |
