From 7ddd8fce064bf84ca36432c19ca0cc0b5b7b34d5 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 11 Oct 2019 19:13:43 +0600 Subject: [PATCH] Format the code --- src/bot/api.rs | 14 +++++------ src/bot/download.rs | 17 ++++--------- src/network/download.rs | 18 +++++++------- src/network/mod.rs | 5 ++-- src/requests/form_builder.rs | 2 +- src/requests/forward_message.rs | 2 +- src/requests/get_chat.rs | 2 +- src/requests/kick_chat_member.rs | 2 +- src/requests/mod.rs | 38 ++++++++++------------------- src/requests/pin_chat_message.rs | 2 +- src/requests/promote_chat_member.rs | 2 ++ src/requests/send_chat_action.rs | 2 +- src/requests/send_document.rs | 8 +++--- src/requests/send_location.rs | 3 ++- src/requests/send_media_group.rs | 4 +-- src/requests/send_photo.rs | 3 +-- src/requests/send_video_note.rs | 6 +++-- src/requests/send_voice.rs | 5 ++-- src/requests/unpin_chat_message.rs | 2 +- src/types/chat_id.rs | 2 +- 20 files changed, 64 insertions(+), 75 deletions(-) diff --git a/src/bot/api.rs b/src/bot/api.rs index 3a692f49..9d8895fc 100644 --- a/src/bot/api.rs +++ b/src/bot/api.rs @@ -1,14 +1,14 @@ use crate::{ bot::Bot, requests::{ - AnswerPreCheckoutQuery, AnswerShippingQuery, - EditMessageLiveLocation, ForwardMessage, GetFile, GetMe, - KickChatMember, PinChatMessage, PromoteChatMember, RestrictChatMember, - SendAudio, SendChatAction, SendContact, SendLocation, SendMediaGroup, - SendMessage, SendPhoto, SendPoll, SendVenue, SendVideoNote, SendVoice, - StopMessageLiveLocation, UnbanChatMember, UnpinChatMessage, + AnswerPreCheckoutQuery, AnswerShippingQuery, EditMessageLiveLocation, + ForwardMessage, GetFile, GetMe, KickChatMember, PinChatMessage, + PromoteChatMember, RestrictChatMember, SendAudio, SendChatAction, + SendContact, SendLocation, SendMediaGroup, SendMessage, SendPhoto, + SendPoll, SendVenue, SendVideoNote, SendVoice, StopMessageLiveLocation, + UnbanChatMember, UnpinChatMessage, }, - types::{ChatPermissions, InputFile, InputMedia, ChatAction, ChatId}, + types::{ChatAction, ChatId, ChatPermissions, InputFile, InputMedia}, }; /// Telegram functions diff --git a/src/bot/download.rs b/src/bot/download.rs index 7918406a..d711f151 100644 --- a/src/bot/download.rs +++ b/src/bot/download.rs @@ -1,17 +1,11 @@ use tokio::io::AsyncWrite; -#[cfg(feature = "unstable-stream")] -use ::{ - bytes::Bytes, - tokio::stream::Stream, -}; -use crate::{ - bot::Bot, - DownloadError, - network::download_file, -}; +#[cfg(feature = "unstable-stream")] +use ::{bytes::Bytes, tokio::stream::Stream}; + #[cfg(feature = "unstable-stream")] use crate::network::download_file_stream; +use crate::{bot::Bot, network::download_file, DownloadError}; impl Bot { /// Download file from telegram into `destination`. @@ -32,8 +26,7 @@ impl Bot { /// let bot = Bot::new("TOKEN"); /// let mut file = File::create("/home/waffle/Pictures/test.png").await?; /// - /// let TgFile { file_path, .. } = - /// bot.get_file("*file_id*").send().await?; + /// let TgFile { file_path, .. } = bot.get_file("*file_id*").send().await?; /// bot.download_file(&file_path, &mut file).await?; /// # Ok(()) } /// ``` diff --git a/src/network/download.rs b/src/network/download.rs index 51891ae2..47061b6f 100644 --- a/src/network/download.rs +++ b/src/network/download.rs @@ -1,10 +1,8 @@ use reqwest::Client; use tokio::io::{AsyncWrite, AsyncWriteExt}; + #[cfg(feature = "unstable-stream")] -use ::{ - tokio::stream::Stream, - bytes::Bytes, -}; +use ::{bytes::Bytes, tokio::stream::Stream}; use crate::DownloadError; @@ -44,11 +42,13 @@ pub async fn download_file_stream( .await? .error_for_status()?; - Ok(futures::stream::unfold(res, |mut res| async { - match res.chunk().await { - Err(err) => Some((Err(err), res)), - Ok(Some(c)) => Some((Ok(c), res)), - Ok(None) => None, + Ok(futures::stream::unfold(res, |mut res| { + async { + match res.chunk().await { + Err(err) => Some((Err(err), res)), + Ok(Some(c)) => Some((Ok(c), res)), + Ok(None) => None, + } } })) } diff --git a/src/network/mod.rs b/src/network/mod.rs index 915f748a..1461304f 100644 --- a/src/network/mod.rs +++ b/src/network/mod.rs @@ -1,10 +1,11 @@ +#[cfg(feature = "unstable-stream")] +pub use download::download_file_stream; + pub use self::{ download::download_file, request::{request_json, request_multipart}, telegram_response::TelegramResponse, }; -#[cfg(feature = "unstable-stream")] -pub use download::download_file_stream; mod download; mod request; diff --git a/src/requests/form_builder.rs b/src/requests/form_builder.rs index e12ac30a..72a013e7 100644 --- a/src/requests/form_builder.rs +++ b/src/requests/form_builder.rs @@ -4,7 +4,7 @@ use reqwest::multipart::Form; use crate::{ requests::utils, - types::{InputMedia, ParseMode, ChatId}, + types::{ChatId, InputMedia, ParseMode}, }; /// This is a convenient struct that builds `reqwest::multipart::Form` diff --git a/src/requests/forward_message.rs b/src/requests/forward_message.rs index 27149a2f..69f81453 100644 --- a/src/requests/forward_message.rs +++ b/src/requests/forward_message.rs @@ -3,7 +3,7 @@ use async_trait::async_trait; use crate::{ network, requests::{Request, RequestContext, ResponseResult}, - types::{ChatId, Message} + types::{ChatId, Message}, }; #[derive(Debug, Clone, Serialize)] diff --git a/src/requests/get_chat.rs b/src/requests/get_chat.rs index 54994b09..a4394bba 100644 --- a/src/requests/get_chat.rs +++ b/src/requests/get_chat.rs @@ -3,7 +3,7 @@ use async_trait::async_trait; use crate::{ network, requests::{Request, RequestContext, ResponseResult}, - types::{ChatId, Chat} + types::{Chat, ChatId}, }; /// Use this method to get up to date information about the chat diff --git a/src/requests/kick_chat_member.rs b/src/requests/kick_chat_member.rs index 85132309..deb6c65e 100644 --- a/src/requests/kick_chat_member.rs +++ b/src/requests/kick_chat_member.rs @@ -3,7 +3,7 @@ use async_trait::async_trait; use crate::{ network, requests::{Request, RequestContext, ResponseResult}, - types::{ChatId, True} + types::{ChatId, True}, }; /// Use this method to kick a user from a group, a supergroup or a channel. In diff --git a/src/requests/mod.rs b/src/requests/mod.rs index 765260b8..a20e1d34 100644 --- a/src/requests/mod.rs +++ b/src/requests/mod.rs @@ -1,40 +1,28 @@ -use async_trait::async_trait; use reqwest::Client; use serde::de::DeserializeOwned; +use async_trait::async_trait; + use crate::RequestError; pub use self::{ answer_pre_checkout_query::AnswerPreCheckoutQuery, answer_shipping_query::AnswerShippingQuery, edit_message_live_location::EditMessageLiveLocation, - forward_message::ForwardMessage, - get_chat::GetChat, - get_file::GetFile, - get_me::GetMe, - get_updates::GetUpdates, + forward_message::ForwardMessage, get_chat::GetChat, get_file::GetFile, + get_me::GetMe, get_updates::GetUpdates, get_user_profile_photos::GetUserProfilePhotos, - kick_chat_member::KickChatMember, - pin_chat_message::PinChatMessage, + kick_chat_member::KickChatMember, pin_chat_message::PinChatMessage, promote_chat_member::PromoteChatMember, - restrict_chat_member::RestrictChatMember, - send_animation::SendAnimation, - send_audio::SendAudio, - send_chat_action::SendChatAction, - send_contact::SendContact, - send_document::SendDocument, - send_location::SendLocation, - send_media_group::SendMediaGroup, - send_message::SendMessage, - send_photo::SendPhoto, - send_poll::SendPoll, - send_venue::SendVenue, - send_video::SendVideo, - send_video_note::SendVideoNote, - send_voice::SendVoice, + restrict_chat_member::RestrictChatMember, send_animation::SendAnimation, + send_audio::SendAudio, send_chat_action::SendChatAction, + send_contact::SendContact, send_document::SendDocument, + send_location::SendLocation, send_media_group::SendMediaGroup, + send_message::SendMessage, send_photo::SendPhoto, send_poll::SendPoll, + send_venue::SendVenue, send_video::SendVideo, + send_video_note::SendVideoNote, send_voice::SendVoice, stop_message_live_location::StopMessageLiveLocation, - unban_chat_member::UnbanChatMember, - unpin_chat_message::UnpinChatMessage, + unban_chat_member::UnbanChatMember, unpin_chat_message::UnpinChatMessage, }; mod form_builder; diff --git a/src/requests/pin_chat_message.rs b/src/requests/pin_chat_message.rs index f541ffa3..5ab517ff 100644 --- a/src/requests/pin_chat_message.rs +++ b/src/requests/pin_chat_message.rs @@ -3,7 +3,7 @@ use async_trait::async_trait; use crate::{ network, requests::{Request, RequestContext, ResponseResult}, - types::{ChatId, True} + types::{ChatId, True}, }; /// Use this method to get up to date information about the chat diff --git a/src/requests/promote_chat_member.rs b/src/requests/promote_chat_member.rs index b80381c4..cbb510fc 100644 --- a/src/requests/promote_chat_member.rs +++ b/src/requests/promote_chat_member.rs @@ -49,6 +49,7 @@ pub struct PromoteChatMember<'a> { #[serde(skip_serializing_if = "Option::is_none")] pub can_promote_members: Option, } + #[async_trait] impl Request for PromoteChatMember<'_> { type ReturnValue = True; @@ -69,6 +70,7 @@ impl PromoteChatMember<'_> { .await } } + impl<'a> PromoteChatMember<'a> { pub(crate) fn new( ctx: RequestContext<'a>, diff --git a/src/requests/send_chat_action.rs b/src/requests/send_chat_action.rs index 04e3a740..c767bb97 100644 --- a/src/requests/send_chat_action.rs +++ b/src/requests/send_chat_action.rs @@ -3,7 +3,7 @@ use async_trait::async_trait; use crate::{ network, requests::{Request, RequestContext, ResponseResult}, - types::{ChatId, True, ChatAction} + types::{ChatAction, ChatId, True}, }; ///Use this method when you need to tell the user that something is happening diff --git a/src/requests/send_document.rs b/src/requests/send_document.rs index a0006d55..7319de44 100644 --- a/src/requests/send_document.rs +++ b/src/requests/send_document.rs @@ -3,7 +3,7 @@ use async_trait::async_trait; use crate::{ network, requests::{Request, RequestContext, ResponseResult}, - types::{ChatId, Message, ParseMode, ReplyMarkup} + types::{ChatId, Message, ParseMode, ReplyMarkup}, }; // TODO: add method to bot/api @@ -22,7 +22,8 @@ pub struct SendDocument<'a> { /// the Telegram servers (recommended), pass an HTTP URL as a String for /// Telegram to get a file from the Internet, or upload a new one using /// multipart/form-data.» - pub document: String, //InputFile or String + pub document: String, + //InputFile or String /// Thumbnail of the file sent; can be ignored if thumbnail generation for /// the file is supported server-side. The thumbnail should be in JPEG /// format and less than 200 kB in size. A thumbnail‘s width and height @@ -32,7 +33,8 @@ pub struct SendDocument<'a> { /// if the thumbnail was uploaded using multipart/form-data under /// . More info on Sending Files » #[serde(skip_serializing_if = "Option::is_none")] - pub thumb: Option, //InputFile or String + pub thumb: Option, + //InputFile or String /// Document caption (may also be used when resending documents by /// file_id), 0-1024 characters #[serde(skip_serializing_if = "Option::is_none")] diff --git a/src/requests/send_location.rs b/src/requests/send_location.rs index 412009cf..72726d5a 100644 --- a/src/requests/send_location.rs +++ b/src/requests/send_location.rs @@ -1,6 +1,7 @@ -use async_trait::async_trait; use serde::Serialize; +use async_trait::async_trait; + use crate::{ network, requests::{Request, RequestContext, ResponseResult}, diff --git a/src/requests/send_media_group.rs b/src/requests/send_media_group.rs index ef6b99c8..6f5e5463 100644 --- a/src/requests/send_media_group.rs +++ b/src/requests/send_media_group.rs @@ -1,11 +1,11 @@ use apply::Apply; + use async_trait::async_trait; use crate::{ network::request_multipart, requests::{ - form_builder::FormBuilder, Request, RequestContext, - ResponseResult, + form_builder::FormBuilder, Request, RequestContext, ResponseResult, }, types::{ChatId, InputFile, InputMedia, Message}, }; diff --git a/src/requests/send_photo.rs b/src/requests/send_photo.rs index d302cc78..db3ca718 100644 --- a/src/requests/send_photo.rs +++ b/src/requests/send_photo.rs @@ -3,8 +3,7 @@ use async_trait::async_trait; use crate::{ network, requests::{ - form_builder::FormBuilder, Request, RequestContext, - ResponseResult, + form_builder::FormBuilder, Request, RequestContext, ResponseResult, }, types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup}, }; diff --git a/src/requests/send_video_note.rs b/src/requests/send_video_note.rs index 8d2f74ce..ff0366fc 100644 --- a/src/requests/send_video_note.rs +++ b/src/requests/send_video_note.rs @@ -20,7 +20,8 @@ pub struct SendVideoNote<'a> { /// exists on the Telegram servers (recommended) or upload a new video /// using multipart/form-data. More info on Sending Files ». Sending video /// notes by a URL is currently unsupported - pub video_note: String, // InputFile or String + pub video_note: String, + // InputFile or String ///Duration of sent video in seconds #[serde(skip_serializing_if = "Option::is_none")] pub duration: Option, @@ -36,7 +37,8 @@ pub struct SendVideoNote<'a> { /// if the thumbnail was uploaded using multipart/form-data under /// . More info on Sending Files » #[serde(skip_serializing_if = "Option::is_none")] - pub thumb: Option, // InputFile or String + pub thumb: Option, + // InputFile or String ///Sends the message silently. Users will receive a notification with no /// sound. #[serde(skip_serializing_if = "Option::is_none")] diff --git a/src/requests/send_voice.rs b/src/requests/send_voice.rs index c219f3df..d9ef624a 100644 --- a/src/requests/send_voice.rs +++ b/src/requests/send_voice.rs @@ -3,7 +3,7 @@ use async_trait::async_trait; use crate::{ network, requests::{Request, RequestContext, ResponseResult}, - types::{ChatId, Message, ParseMode, ReplyMarkup} + types::{ChatId, Message, ParseMode, ReplyMarkup}, }; ///Use this method to send audio files, if you want Telegram clients to display @@ -23,7 +23,8 @@ pub struct SendVoice<'a> { /// on the Telegram servers (recommended), pass an HTTP URL as a String for /// Telegram to get a file from the Internet, or upload a new one using /// multipart/form-data. More info on Sending Files » - pub voice: String, //InputFile or String + pub voice: String, + //InputFile or String /// Voice message caption, 0-1024 characters #[serde(skip_serializing_if = "Option::is_none")] pub caption: Option, diff --git a/src/requests/unpin_chat_message.rs b/src/requests/unpin_chat_message.rs index e2823aca..0c8a68df 100644 --- a/src/requests/unpin_chat_message.rs +++ b/src/requests/unpin_chat_message.rs @@ -3,7 +3,7 @@ use async_trait::async_trait; use crate::{ network, requests::{Request, RequestContext, ResponseResult}, - types::{ChatId, True} + types::{ChatId, True}, }; #[derive(Debug, Clone, Serialize)] diff --git a/src/types/chat_id.rs b/src/types/chat_id.rs index 470a4147..c6e69093 100644 --- a/src/types/chat_id.rs +++ b/src/types/chat_id.rs @@ -29,7 +29,7 @@ mod tests { let actual_json = serde_json::to_string(&ChatId::ChannelUsername( String::from("@username"), )) - .unwrap(); + .unwrap(); assert_eq!(expected_json, actual_json) }