diff options
| author | Ubuntu <github@matdoes.dev> | 2023-02-10 18:06:18 +0000 |
|---|---|---|
| committer | Ubuntu <github@matdoes.dev> | 2023-02-10 18:06:18 +0000 |
| commit | f5ae1b97171473c3c2db99d92062a18a8313541e (patch) | |
| tree | 11f90f40a7894a4c569741b2cc77d0707449f64d /azalea/src/lib.rs | |
| parent | 7e43e6d24a106fc9b1894a170db16b4f21ff8dad (diff) | |
| download | azalea-drasl-f5ae1b97171473c3c2db99d92062a18a8313541e.tar.xz | |
fix and improve examples in docs
Diffstat (limited to 'azalea/src/lib.rs')
| -rw-r--r-- | azalea/src/lib.rs | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/azalea/src/lib.rs b/azalea/src/lib.rs index b7707b92..a34ea179 100644 --- a/azalea/src/lib.rs +++ b/azalea/src/lib.rs @@ -4,7 +4,7 @@ mod bot; pub mod pathfinder; pub mod prelude; -mod swarm; +pub mod swarm; pub use azalea_block as blocks; pub use azalea_client::*; @@ -23,7 +23,6 @@ use protocol::{ resolver::{self, ResolverError}, ServerAddress, }; -pub use swarm::*; use thiserror::Error; use tokio::sync::mpsc; @@ -43,10 +42,19 @@ pub enum StartError { /// making Azalea bots. /// /// ```no_run -/// azalea::ClientBuilder::new() +/// # use azalea::prelude::*; +/// # #[tokio::main] +/// # async fn main() { +/// ClientBuilder::new() /// .set_handler(handle) /// .start(Account::offline("bot"), "localhost") /// .await; +/// # } +/// # #[derive(Component, Clone, Default)] +/// # pub struct State; +/// # async fn handle(mut bot: Client, event: Event, state: State) -> anyhow::Result<()> { +/// # Ok(()) +/// # } /// ``` pub struct ClientBuilder<S, Fut> where @@ -79,9 +87,20 @@ where /// Set the function that's called every time a bot receives an [`Event`]. /// This is the way to handle normal per-bot events. /// - /// You can only have one client handler, calling this again will replace - /// the old client handler function (you can have a client handler and swarm - /// handler separately though). + /// You must have exactly one client handler, calling this again will + /// replace the old client handler function. + /// + /// ``` + /// # use azalea::prelude::*; + /// # let client_builder = azalea::ClientBuilder::new(); + /// client_builder.set_handler(handle); + /// + /// # #[derive(Component, Clone, Default)] + /// # pub struct State; + /// async fn handle(mut bot: Client, event: Event, state: State) -> anyhow::Result<()> { + /// Ok(()) + /// } + /// ``` #[must_use] pub fn set_handler(mut self, handler: HandleFn<Fut, S>) -> Self { self.handler = Some(handler); |
