fmt + doc fixes

This commit is contained in:
Waffle 2019-11-27 17:07:13 +03:00
parent ef15a4167f
commit 9b8d9eba9b
24 changed files with 109 additions and 92 deletions

View file

@ -1,10 +1,10 @@
use crate::{
Bot,
requests::{
json, multipart,
payloads::{GetMe, GetUpdates, SendMessage, SendAnimation, GetFile}
payloads::{GetFile, GetMe, GetUpdates, SendAnimation, SendMessage},
},
types::{ChatId, InputFile},
Bot,
};
impl Bot {
@ -29,8 +29,11 @@ impl Bot {
/// For tg-method documentation see [`SendMessage`]
///
/// [`SendMessage`]: crate::requests::payloads::SendMessage
pub fn send_message<C, T>(&self, chat_id: C, text: T)
-> json::Request<SendMessage>
pub fn send_message<C, T>(
&self,
chat_id: C,
text: T,
) -> json::Request<SendMessage>
where
C: Into<ChatId>,
T: Into<String>,
@ -41,8 +44,11 @@ impl Bot {
/// For tg-method documentation see [`SendAnimation`]
///
/// [`SendAnimation`]: crate::requests::payloads::SendAnimation
pub fn send_animation<C>(&self, chat_id: C, animation: InputFile)
-> multipart::Request<SendAnimation>
pub fn send_animation<C>(
&self,
chat_id: C,
animation: InputFile,
) -> multipart::Request<SendAnimation>
where
C: Into<ChatId>,
{
@ -58,4 +64,4 @@ impl Bot {
{
json::Request::new(self, GetFile::new(file_id))
}
}
}

View file

@ -1,9 +1,9 @@
use serde::de::DeserializeOwned;
use crate::{
Bot,
requests::{dynamic, json, multipart, ResponseResult},
network::{request_dynamic, request_json, request_multipart},
requests::{dynamic, json, multipart, ResponseResult},
Bot,
};
impl Bot {
@ -30,7 +30,7 @@ impl Bot {
/// [`execute_multipart`]: self::Bot::execute_multipart
pub async fn execute_dyn<O>(
&self,
payload: &dyn dynamic::Payload<Output = O>
payload: &dyn dynamic::Payload<Output = O>,
) -> ResponseResult<O>
where
O: DeserializeOwned,
@ -39,8 +39,9 @@ impl Bot {
self.client(),
self.token(),
payload.name(),
payload.kind()
).await
payload.kind(),
)
.await
}
/// Execute json-request
@ -57,7 +58,10 @@ impl Bot {
///
/// **NOTE**: we recommend to use
/// `bot.send_message(id, "text").send().await` instead
pub async fn execute_json<P>(&self, payload: &P) -> ResponseResult<P::Output>
pub async fn execute_json<P>(
&self,
payload: &P,
) -> ResponseResult<P::Output>
where
P: json::Payload,
P::Output: DeserializeOwned,
@ -82,7 +86,10 @@ impl Bot {
///
/// **NOTE**: we recommend to use
/// `bot.send_animation(id, InputFile::...).send().await` instead
pub async fn execute_multipart<P>(&self, payload: &P) -> ResponseResult<P::Output>
pub async fn execute_multipart<P>(
&self,
payload: &P,
) -> ResponseResult<P::Output>
where
P: multipart::Payload,
P::Output: DeserializeOwned,
@ -91,7 +98,8 @@ impl Bot {
self.client(),
self.token(),
P::NAME,
payload.payload()
).await
payload.payload(),
)
.await
}
}

View file

@ -38,7 +38,6 @@ type FiltersAndHandlers<'a, T, E> = Vec<FilterAndHandler<'a, T, E>>;
/// - Error (`E` generic parameter) _must_ implement [`std::fmt::Debug`]
/// - All 'handlers' are boxed
/// - Handler's fututres are also boxed
/// - [Custom error policy] is also boxed
/// - All errors from [updater] are ignored (TODO: remove this limitation)
/// - All handlers executed in order (this means that in dispatching have 2
/// upadtes it will first execute some handler into complition with first
@ -86,9 +85,7 @@ type FiltersAndHandlers<'a, T, E> = Vec<FilterAndHandler<'a, T, E>>;
/// ```
///
/// [`std::fmt::Debug`]: std::fmt::Debug
/// [Custom error policy]:
/// crate::dispatching::filter::error_policy::ErrorPolicy::Custom [updater]:
/// crate::dispatching::updater
/// [updater]: crate::dispatching::updater
pub struct FilterDispatcher<'a, E, Ep> {
message_handlers: FiltersAndHandlers<'a, Message, E>,
edited_message_handlers: FiltersAndHandlers<'a, Message, E>,

View file

@ -79,7 +79,7 @@ where
/// assert_eq!(and(true, false).test(&()), false);
/// ```
///
/// [`And::new`]: crate::dispatching::filter::And::new
/// [`And::new`]: crate::dispatching::filters::And::new
pub fn and<A, B>(a: A, b: B) -> And<A, B> {
And::new(a, b)
}
@ -130,7 +130,7 @@ where
/// assert_eq!(or(false, false).test(&()), false);
/// ```
///
/// [`Or::new`]: crate::dispatching::filter::Or::new
/// [`Or::new`]: crate::dispatching::filters::Or::new
pub fn or<A, B>(a: A, b: B) -> Or<A, B> {
Or::new(a, b)
}
@ -175,7 +175,7 @@ where
/// assert_eq!(not(true).test(&()), false);
/// ```
///
/// [`Not::new`]: crate::dispatching::filter::Not::new
/// [`Not::new`]: crate::dispatching::filters::Not::new
pub fn not<A>(a: A) -> Not<A> {
Not::new(a)
}
@ -199,7 +199,7 @@ pub fn not<A>(a: A) -> Not<A> {
/// assert_eq!(all![false, false].test(&()), false);
/// ```
///
/// [filter]: crate::dispatching::filter::Filter
/// [filter]: crate::dispatching::filters::Filter
#[macro_export]
macro_rules! all {
($one:expr) => { $one };
@ -230,7 +230,7 @@ macro_rules! all {
/// assert_eq!(any![false, false, false].test(&()), false);
/// ```
///
/// [filter]: crate::dispatching::filter::Filter
/// [filter]: crate::dispatching::filters::Filter
#[macro_export]
macro_rules! any {
($one:expr) => { $one };
@ -277,7 +277,7 @@ pub struct F<A>(A);
/// Constructor fn for [F]
///
/// [F]: crate::dispatching::filter::F;
/// [F]: crate::dispatching::filters::F;
pub fn f<A>(a: A) -> F<A> {
F(a)
}
@ -322,7 +322,7 @@ pub trait FilterExt<T> {
/// assert_eq!(flt.test(&1), false);
/// ```
///
/// [`Not::new`]: crate::dispatching::filter::Not::new
/// [`Not::new`]: crate::dispatching::filters::Not::new
fn not(self) -> Not<Self>
where
Self: Sized,
@ -344,7 +344,7 @@ pub trait FilterExt<T> {
/// assert_eq!(flt.test(&43), false);
/// ```
///
/// [`Not::new`]: crate::dispatching::filter::And::new
/// [`Not::new`]: crate::dispatching::filters::And::new
fn and<B>(self, other: B) -> And<Self, B>
where
Self: Sized,
@ -366,7 +366,7 @@ pub trait FilterExt<T> {
/// assert_eq!(flt.test(&17), false);
/// ```
///
/// [`Not::new`]: crate::dispatching::filter::Or::new
/// [`Not::new`]: crate::dispatching::filters::Or::new
fn or<B>(self, other: B) -> Or<Self, B>
where
Self: Sized,

View file

@ -13,9 +13,9 @@ use crate::{dispatching::Filter, types::Message};
/// If you want to compare text and caption use
/// [MessageTextCaptionFilter]
///
/// [MessageTextFilter]: telebofr::dispatching::filters::MessageTextFilter
/// [MessageTextFilter]: crate::dispatching::filters::MessageTextFilter
/// [MessageTextCaptionFilter]:
/// telebofr::dispatching::filters::MessageTextCaptionFilter
/// crate::dispatching::filters::MessageTextCaptionFilter
pub struct MessageCaptionFilter {
text: String,
}

View file

@ -11,9 +11,9 @@ use crate::{dispatching::Filter, types::Message};
/// If you want to compare text and caption use
/// [MessageTextCaptionFilter]
///
/// [MessageCaptionFilter]: telebofr::dispatching::filters::MessageCaptionFilter
/// [MessageCaptionFilter]: crate::dispatching::filters::MessageCaptionFilter
/// [MessageTextCaptionFilter]:
/// telebofr::dispatching::filters::MessageTextCaptionFilter
/// crate::dispatching::filters::MessageTextCaptionFilter
pub struct MessageTextFilter {
text: String,
}

View file

@ -13,8 +13,8 @@ use crate::{dispatching::Filter, types::Message};
/// If you want to compare only text use
/// [MessageTextFilter]
///
/// [MessageCaptionFilter]: telebofr::dispatching::filters::MessageCaptionFilter
/// [MessageTextFilter]: telebofr::filter::filters::MessageTextFilter
/// [MessageCaptionFilter]: crate::dispatching::filters::MessageCaptionFilter
/// [MessageTextFilter]: crate::dispatching::filters::MessageTextFilter
pub struct MessageTextCaptionFilter {
text: String,
}

View file

@ -93,7 +93,7 @@ use crate::{bot::Bot, types::Update, RequestError};
/// <a id="4" href="#4b">^4</a> `offset = N` means that we've already received
/// updates `0..=N`
///
/// [GetUpdates]: crate::requests::GetUpdates
/// [GetUpdates]: crate::requests::payloads::GetUpdates
/// [getting updates]: https://core.telegram.org/bots/api#getting-updates
/// [wiki]: https://en.wikipedia.org/wiki/Push_technology#Long_polling
pub trait Updater:

View file

@ -3,7 +3,7 @@ pub use download::download_file_stream;
pub use self::{
download::download_file,
request::{request_json, request_multipart, request_dynamic},
request::{request_dynamic, request_json, request_multipart},
telegram_response::TelegramResponse,
};

View file

@ -69,19 +69,16 @@ pub async fn request_dynamic<T>(
method_name: &str,
params: crate::requests::dynamic::Kind,
) -> ResponseResult<T>
where
T: DeserializeOwned,
where
T: DeserializeOwned,
{
use crate::requests::dynamic::Kind;
match params {
Kind::Json(str) => request_body(client, token, method_name, str).await,
Kind::Multipart(form) => request_multipart(
client,
token,
method_name,
form
).await
Kind::Multipart(form) => {
request_multipart(client, token, method_name, form).await
}
}
}

View file

@ -1,8 +1,8 @@
use serde::de::DeserializeOwned;
use reqwest::multipart;
use serde::de::DeserializeOwned;
use crate::{Bot, network};
use super::{ResponseResult, DynMethod};
use super::{DynMethod, ResponseResult};
use crate::{network, Bot};
/// [`Payload`] kind. Used to determinate the way for sending request.
pub enum Kind {
@ -49,6 +49,7 @@ where
self.bot.token(),
self.payload.name(),
self.payload.kind(),
).await
)
.await
}
}

View file

@ -1,7 +1,7 @@
use serde::{de::DeserializeOwned, Serialize};
use crate::{Bot, network};
use super::{ResponseResult, Method};
use super::{Method, ResponseResult};
use crate::{network, Bot};
pub trait Payload: Serialize + Method {}
@ -36,6 +36,7 @@ where
self.bot.token(),
P::NAME,
&self.payload,
).await
)
.await
}
}

View file

@ -3,10 +3,9 @@
mod form_builder;
mod utils;
pub mod dynamic;
pub mod json;
pub mod multipart;
pub mod dynamic;
/// A type that is returned when making requests to telegram
pub type ResponseResult<T> = Result<T, crate::RequestError>;
@ -43,7 +42,7 @@ pub trait DynMethod {
impl<T> DynMethod for T
where
T: Method
T: Method,
{
type Output = T::Output;
@ -52,13 +51,14 @@ where
}
}
#[rustfmt::skip]
pub mod payloads {
// payloads are sorted as in tg docs (https://core.telegram.org/bots/api)
// Getting updates
mod get_updates;
pub use get_updates::{GetUpdates, AllowedUpdate};
pub use get_updates::{AllowedUpdate, GetUpdates};
// Available methods
mod get_me;

View file

@ -1,8 +1,8 @@
use serde::de::DeserializeOwned;
use reqwest::multipart;
use serde::de::DeserializeOwned;
use crate::{Bot, network};
use super::{ResponseResult, Method};
use super::{Method, ResponseResult};
use crate::{network, Bot};
pub trait Payload: Method {
fn payload(&self) -> multipart::Form;
@ -38,6 +38,7 @@ where
self.bot.token(),
P::NAME,
self.payload.payload(),
).await
)
.await
}
}

View file

@ -1,8 +1,7 @@
use crate::{
requests::{json, Method},
requests::{dynamic, json, Method},
types::File,
};
use crate::requests::dynamic;
/// Use this method to get basic info about a file and prepare it for
/// downloading.
@ -47,7 +46,7 @@ impl dynamic::Payload for GetFile {
impl GetFile {
pub fn new<F>(file_id: F) -> Self
where
F: Into<String>
F: Into<String>,
{
Self {
file_id: file_id.into(),

View file

@ -1,10 +1,11 @@
use crate::{
requests::{Method, dynamic},
requests::{dynamic, json, Method},
types::User,
};
use crate::requests::json;
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Default, Deserialize, Serialize)]
#[derive(
Debug, PartialEq, Eq, Hash, Clone, Copy, Default, Deserialize, Serialize,
)]
/// A filter method for testing your bot's auth token. Requires no parameters.
/// Returns basic information about the bot in form of a [`User`] object.
///

View file

@ -1,5 +1,5 @@
use crate::{
requests::{json, Method, dynamic},
requests::{dynamic, json, Method},
types::Update,
};
@ -20,10 +20,11 @@ pub struct GetUpdates {
/// Identifier of the first update to be returned. Must be greater by one
/// than the highest among the identifiers of previously received updates.
/// By default, updates starting with the earliest unconfirmed update are
/// returned. An update is considered confirmed as soon as [`GetUpdates`] is
/// called with an [`offset`] higher than its [`id`]. The negative offset
/// can be specified to retrieve updates starting from `-offset` update from
/// the end of the updates queue. All previous updates will forgotten.
/// returned. An update is considered confirmed as soon as [`GetUpdates`]
/// is called with an [`offset`] higher than its [`id`]. The negative
/// offset can be specified to retrieve updates starting from `-offset`
/// update from the end of the updates queue. All previous updates will
/// forgotten.
///
/// [`GetUpdates`]: self::GetUpdates
/// [`offset`]: self::GetUpdates::offset

View file

@ -1,7 +1,7 @@
use reqwest::multipart::Form;
use crate::{
requests::{multipart, Method, dynamic, form_builder::FormBuilder},
requests::{dynamic, form_builder::FormBuilder, multipart, Method},
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
};
@ -42,7 +42,8 @@ pub struct SendAnimation {
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]: crate::types::ParseMode
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub parse_mode: Option<ParseMode>,
/// Sends the message silently. Users will receive a notification with no
/// sound.

View file

@ -1,5 +1,5 @@
use crate::{
requests::{json, Method, dynamic},
requests::{dynamic, json, Method},
types::{ChatId, Message, ParseMode, ReplyMarkup},
};
@ -21,7 +21,8 @@ pub struct SendMessage {
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]: crate::types::ParseMode
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub parse_mode: Option<ParseMode>,
/// Disables link previews for links in this message
pub disable_web_page_preview: Option<bool>,

View file

@ -1,6 +1,8 @@
/// Unique identifier for the target chat or username of the target channel (in
/// the format `@channelusername`)
#[derive(Debug, Display, PartialEq, Eq, Hash, Clone, Deserialize, Serialize, From)]
#[derive(
Debug, Display, PartialEq, Eq, Hash, Clone, Deserialize, Serialize, From,
)]
#[serde(untagged)]
pub enum ChatId {
/// chat identifier

View file

@ -14,9 +14,9 @@ pub enum InputMessageContent {
/// Text of the message to be sent, 1-4096 characters
message_text: String,
/// Send [Markdown] or [HTML],
/// if you want Telegram apps to show [bold, italic, fixed-width text
/// or inline URLs] in the media caption.
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in the media
/// caption.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML

View file

@ -82,6 +82,14 @@ pub enum Sender {
Signature(String),
}
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub enum ForwardedFrom {
#[serde(rename = "forward_from")]
User(User),
#[serde(rename = "forward_sender_name")]
SenderName(String),
}
#[derive(Debug, Deserialize, PartialEq, Clone)]
#[serde(untagged)]
pub enum ForwardKind {
@ -106,14 +114,6 @@ pub enum ForwardKind {
},
}
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub enum ForwardedFrom {
#[serde(rename = "forward_from")]
User(User),
#[serde(rename = "forward_sender_name")]
SenderName(String),
}
#[derive(Debug, Deserialize, PartialEq, Clone)]
#[serde(untagged)]
pub enum MediaKind {

View file

@ -67,7 +67,7 @@ use serde::{Deserialize, Serialize};
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [SendMessage]: crate::requests::SendMessage
/// [SendMessage]: crate::requests::payloads::SendMessage
pub enum ParseMode {
HTML,
Markdown,

View file

@ -9,9 +9,10 @@ use crate::types::True;
/// [`ReplyKeyboardMarkup`]: crate::types::ReplyKeyboardMarkup
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
pub struct ReplyKeyboardRemove {
/// Requests clients to remove the custom keyboard (user will not be able to
/// summon this keyboard; if you want to hide the keyboard from sight but
/// keep it accessible, use one_time_keyboard in ReplyKeyboardMarkup)
/// Requests clients to remove the custom keyboard (user will not be able
/// to summon this keyboard; if you want to hide the keyboard from
/// sight but keep it accessible, use one_time_keyboard in
/// ReplyKeyboardMarkup)
pub remove_keyboard: True,
/// Optional. Use this parameter if you want to show the keyboard to
@ -28,7 +29,7 @@ pub struct ReplyKeyboardRemove {
/// the group dont see the keyboard.
///
/// [`Message`]: crate::types::Message
/// [`reply_to_message_id`]: crate::types::Message::reply_to_message_id
/// [`reply_to_message_id`]: crate::types::ForwardKind::Origin
#[serde(skip_serializing_if = "Option::is_none")]
pub selective: Option<bool>,
}