mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-10 20:12:25 +01:00
Document BotBuilder
This commit is contained in:
parent
5a73654e13
commit
772088abd3
3 changed files with 22 additions and 4 deletions
|
@ -19,6 +19,7 @@ impl Bot {
|
||||||
/// If cannot get the `TELOXIDE_TOKEN` environmental variable.
|
/// If cannot get the `TELOXIDE_TOKEN` environmental variable.
|
||||||
///
|
///
|
||||||
/// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html
|
/// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html
|
||||||
|
#[allow(deprecated)]
|
||||||
pub fn from_env() -> Arc<Self> {
|
pub fn from_env() -> Arc<Self> {
|
||||||
Self::from_env_with_client(Client::new())
|
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
|
/// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html
|
||||||
#[deprecated]
|
#[deprecated]
|
||||||
|
#[allow(deprecated)]
|
||||||
pub fn from_env_with_client(client: Client) -> Arc<Self> {
|
pub fn from_env_with_client(client: Client) -> Arc<Self> {
|
||||||
Self::with_client(
|
Self::with_client(
|
||||||
&std::env::var("TELOXIDE_TOKEN")
|
&std::env::var("TELOXIDE_TOKEN")
|
||||||
|
@ -44,6 +46,7 @@ impl Bot {
|
||||||
///
|
///
|
||||||
/// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html
|
/// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html
|
||||||
#[deprecated]
|
#[deprecated]
|
||||||
|
#[allow(deprecated)]
|
||||||
pub fn new<S>(token: S) -> Arc<Self>
|
pub fn new<S>(token: S) -> Arc<Self>
|
||||||
where
|
where
|
||||||
S: Into<String>,
|
S: Into<String>,
|
||||||
|
@ -56,6 +59,7 @@ impl Bot {
|
||||||
///
|
///
|
||||||
/// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html
|
/// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html
|
||||||
#[deprecated]
|
#[deprecated]
|
||||||
|
#[allow(deprecated)]
|
||||||
pub fn with_client<S>(token: S, client: Client) -> Arc<Self>
|
pub fn with_client<S>(token: S, client: Client) -> Arc<Self>
|
||||||
where
|
where
|
||||||
S: Into<String>,
|
S: Into<String>,
|
||||||
|
@ -76,8 +80,8 @@ impl Bot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
struct BotBuilder {
|
pub struct BotBuilder {
|
||||||
token: Option<String>,
|
token: Option<String>,
|
||||||
client: Option<Client>,
|
client: Option<Client>,
|
||||||
}
|
}
|
||||||
|
@ -88,14 +92,19 @@ impl BotBuilder {
|
||||||
Self { token: None, client: None }
|
Self { token: None, client: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Specifies a custom HTTPS client. Otherwise, the default will be used.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn client(mut self, client: Client) -> Self {
|
pub fn client(mut self, client: Client) -> Self {
|
||||||
self.client = Some(client);
|
self.client = Some(client);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Specified a custom token.
|
||||||
|
///
|
||||||
|
/// Otherwise, a token will be extracted from the `TELOXIDE_TOKEN`
|
||||||
|
/// environmental variable.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn token(mut self, token: S) -> Self
|
pub fn token<S>(mut self, token: S) -> Self
|
||||||
where
|
where
|
||||||
S: Into<String>,
|
S: Into<String>,
|
||||||
{
|
{
|
||||||
|
@ -103,6 +112,14 @@ impl BotBuilder {
|
||||||
self
|
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]
|
#[must_use]
|
||||||
pub fn build(self) -> Bot {
|
pub fn build(self) -> Bot {
|
||||||
Bot {
|
Bot {
|
||||||
|
|
|
@ -188,6 +188,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
#[allow(deprecated)]
|
||||||
async fn updates_from_same_chat_executed_sequentially() {
|
async fn updates_from_same_chat_executed_sequentially() {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct MyUpdate {
|
struct MyUpdate {
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
)]
|
)]
|
||||||
#![allow(clippy::match_bool)]
|
#![allow(clippy::match_bool)]
|
||||||
|
|
||||||
pub use bot::Bot;
|
pub use bot::{Bot, BotBuilder};
|
||||||
pub use errors::{ApiErrorKind, DownloadError, RequestError};
|
pub use errors::{ApiErrorKind, DownloadError, RequestError};
|
||||||
|
|
||||||
mod errors;
|
mod errors;
|
||||||
|
|
Loading…
Reference in a new issue