From 772088abd37510cc4d5f0fe55387cb5fd47406a3 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Thu, 16 Jul 2020 19:14:32 +0600 Subject: [PATCH] Document BotBuilder --- src/bot/mod.rs | 23 ++++++++++++++++--- .../dialogue/dialogue_dispatcher.rs | 1 + src/lib.rs | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/bot/mod.rs b/src/bot/mod.rs index eaba569d..6a357b17 100644 --- a/src/bot/mod.rs +++ b/src/bot/mod.rs @@ -19,6 +19,7 @@ impl Bot { /// If cannot get the `TELOXIDE_TOKEN` environmental variable. /// /// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html + #[allow(deprecated)] pub fn from_env() -> Arc { Self::from_env_with_client(Client::new()) } @@ -31,6 +32,7 @@ impl Bot { /// /// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html #[deprecated] + #[allow(deprecated)] pub fn from_env_with_client(client: Client) -> Arc { Self::with_client( &std::env::var("TELOXIDE_TOKEN") @@ -44,6 +46,7 @@ impl Bot { /// /// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html #[deprecated] + #[allow(deprecated)] pub fn new(token: S) -> Arc where S: Into, @@ -56,6 +59,7 @@ impl Bot { /// /// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html #[deprecated] + #[allow(deprecated)] pub fn with_client(token: S, client: Client) -> Arc where S: Into, @@ -76,8 +80,8 @@ impl Bot { } } -#[derive(Debug)] -struct BotBuilder { +#[derive(Debug, Default)] +pub struct BotBuilder { token: Option, client: Option, } @@ -88,14 +92,19 @@ impl BotBuilder { Self { token: None, client: None } } + /// Specifies a custom HTTPS client. Otherwise, the default will be used. #[must_use] pub fn client(mut self, client: Client) -> Self { self.client = Some(client); self } + /// Specified a custom token. + /// + /// Otherwise, a token will be extracted from the `TELOXIDE_TOKEN` + /// environmental variable. #[must_use] - pub fn token(mut self, token: S) -> Self + pub fn token(mut self, token: S) -> Self where S: Into, { @@ -103,6 +112,14 @@ impl BotBuilder { self } + /// Builds [`Bot`]. + /// + /// # Panics + /// If cannot get the `TELOXIDE_TOKEN` environmental variable. + /// + /// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html + /// + /// [`Bot`]: crate::Bot #[must_use] pub fn build(self) -> Bot { Bot { diff --git a/src/dispatching/dialogue/dialogue_dispatcher.rs b/src/dispatching/dialogue/dialogue_dispatcher.rs index 385545c2..6df9377b 100644 --- a/src/dispatching/dialogue/dialogue_dispatcher.rs +++ b/src/dispatching/dialogue/dialogue_dispatcher.rs @@ -188,6 +188,7 @@ mod tests { }; #[tokio::test] + #[allow(deprecated)] async fn updates_from_same_chat_executed_sequentially() { #[derive(Debug)] struct MyUpdate { diff --git a/src/lib.rs b/src/lib.rs index 65d62808..be9f7807 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,7 +15,7 @@ )] #![allow(clippy::match_bool)] -pub use bot::Bot; +pub use bot::{Bot, BotBuilder}; pub use errors::{ApiErrorKind, DownloadError, RequestError}; mod errors;