diff --git a/src/bot/api.rs b/src/bot/api.rs index 1d743a15..0e56cc24 100644 --- a/src/bot/api.rs +++ b/src/bot/api.rs @@ -358,11 +358,7 @@ impl Bot { SendAnimation::new(self, chat_id, animation) } - pub fn set_chat_title<C, T>( - &self, - chat_id: C, - title: T, - ) -> SetChatTitle + pub fn set_chat_title<C, T>(&self, chat_id: C, title: T) -> SetChatTitle where C: Into<ChatId>, T: Into<String>, diff --git a/src/bot/download.rs b/src/bot/download.rs index dd2d5566..b768f43d 100644 --- a/src/bot/download.rs +++ b/src/bot/download.rs @@ -19,7 +19,7 @@ impl Bot { /// use telebofr::types::File as TgFile; /// use tokio::fs::File; /// # use telebofr::RequestError; - /// use telebofr::bot::Bot; + /// use telebofr::Bot; /// /// # async fn run() -> Result<(), Box<dyn std::error::Error>> { /// let bot = Bot::new("TOKEN"); diff --git a/src/bot/mod.rs b/src/bot/mod.rs index d4e6d884..f2b45f51 100644 --- a/src/bot/mod.rs +++ b/src/bot/mod.rs @@ -1,38 +1,44 @@ -//! A Telegram bot. - use reqwest::Client; mod api; mod download; +/// A Telegram bot used to build requests. #[derive(Debug, Clone)] pub struct Bot { token: String, client: Client, } -/// Constructors impl Bot { - pub fn new(token: &str) -> Self { + pub fn new<S>(token: S) -> Self + where + S: Into<String>, + { Bot { - token: String::from(token), + token: token.into(), client: Client::new(), } } - pub fn with_client(token: &str, client: Client) -> Self { + pub fn with_client<S>(token: S, client: Client) -> Self + where + S: Into<String>, + { Bot { - token: String::from(token), + token: token.into(), client, } } } impl Bot { + #[inline] pub fn token(&self) -> &str { &self.token } + #[inline] pub fn client(&self) -> &Client { &self.client } diff --git a/src/dispatcher/simple/mod.rs b/src/dispatcher/simple/mod.rs index 34fca780..5c7048f5 100644 --- a/src/dispatcher/simple/mod.rs +++ b/src/dispatcher/simple/mod.rs @@ -32,7 +32,7 @@ type Handlers<'a, T, E> = /// /// Simplest example: /// ```no_run -/// # use telebofr::bot::Bot; +/// # use telebofr::Bot; /// use telebofr::types::Message; /// async fn run() { /// use std::convert::Infallible; diff --git a/src/lib.rs b/src/lib.rs index 8d244ff6..533071c7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,12 +5,13 @@ extern crate serde; #[macro_use] extern crate thiserror; +pub use bot::Bot; pub use errors::{DownloadError, RequestError}; mod errors; mod network; -pub mod bot; +mod bot; pub mod dispatcher; pub mod requests; pub mod types; diff --git a/src/requests/mod.rs b/src/requests/mod.rs index 013d3707..3ed8a93d 100644 --- a/src/requests/mod.rs +++ b/src/requests/mod.rs @@ -1,4 +1,4 @@ -//! Raw API functions. +//! API requests. use async_trait::async_trait; use serde::de::DeserializeOwned; diff --git a/src/requests/set_chat_title.rs b/src/requests/set_chat_title.rs index 494e9acc..adb94576 100644 --- a/src/requests/set_chat_title.rs +++ b/src/requests/set_chat_title.rs @@ -1,9 +1,11 @@ use async_trait::async_trait; -use crate::bot::Bot; -use crate::types::{ChatId, True}; -use crate::requests::{Request, ResponseResult}; -use crate::network; +use crate::{ + bot::Bot, + network, + requests::{Request, ResponseResult}, + types::{ChatId, True}, +}; #[derive(Debug, Clone, Serialize)] pub struct SetChatTitle<'a> { @@ -29,8 +31,9 @@ impl SetChatTitle<'_> { &self.bot.client(), &self.bot.token(), "setChatTitle", - &self - ).await + &self, + ) + .await } } @@ -52,16 +55,16 @@ impl<'a> SetChatTitle<'a> { } pub fn chat_id<C>(mut self, chat_id: C) -> Self - where - C: Into<ChatId>, + where + C: Into<ChatId>, { self.chat_id = chat_id.into(); self } pub fn title<C>(mut self, title: C) -> Self - where - C: Into<String>, + where + C: Into<String>, { self.title = title.into(); self diff --git a/src/types/mod.rs b/src/types/mod.rs index 62dbe9b9..e1f08e4f 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -1,4 +1,4 @@ -//! Raw API structures. +//! API types. pub use animation::*; pub use audio::*;