From f95ea5ee31e281b7bc231d57e60012fee35fe1a9 Mon Sep 17 00:00:00 2001 From: Waffle Date: Sat, 21 Sep 2019 00:57:17 +0300 Subject: [PATCH] cargo fmt --- src/bot/download.rs | 9 ++------- src/network/download.rs | 13 ++++++------ src/network/request.rs | 22 ++++++++++----------- src/requests/edit_message_live_location.rs | 4 +++- src/requests/get_chat.rs | 23 +++++++++++----------- src/requests/get_file.rs | 1 - src/requests/send_audio.rs | 3 ++- src/requests/send_chat_action.rs | 2 +- src/requests/send_contact.rs | 5 +++-- src/requests/send_media_group.rs | 1 - src/requests/send_poll.rs | 5 +++-- src/requests/send_venue.rs | 5 +++-- src/types/callback_game.rs | 2 +- src/types/login_url.rs | 2 +- 14 files changed, 48 insertions(+), 49 deletions(-) diff --git a/src/bot/download.rs b/src/bot/download.rs index beef6fc9..31f77bfd 100644 --- a/src/bot/download.rs +++ b/src/bot/download.rs @@ -1,17 +1,12 @@ use reqwest::r#async::Chunk; -use tokio::{ - io::AsyncWrite, - stream::Stream, -}; - +use tokio::{io::AsyncWrite, stream::Stream}; use crate::{ - DownloadError, bot::Bot, network::{download_file, download_file_stream}, + DownloadError, }; - impl Bot { /// Download file from telegram into `destination`. /// `path` can be obtained from [`get_file`] method. diff --git a/src/network/download.rs b/src/network/download.rs index 7345e87f..3f1de111 100644 --- a/src/network/download.rs +++ b/src/network/download.rs @@ -1,23 +1,22 @@ -use reqwest::r#async::{Client, Chunk}; +use reqwest::r#async::{Chunk, Client}; use tokio::{ - stream::Stream, io::{AsyncWrite, AsyncWriteExt}, + stream::Stream, }; use crate::{ + network::{file_url, TELEGRAM_API_URL}, DownloadError, - network::{TELEGRAM_API_URL, file_url}, }; - pub async fn download_file( client: &Client, token: &str, path: &str, destination: &mut D, ) -> Result<(), DownloadError> - where - D: AsyncWrite + Unpin, +where + D: AsyncWrite + Unpin, { let mut stream = download_file_stream(client, token, path).await?; @@ -36,4 +35,4 @@ pub(crate) async fn download_file_stream( let url = file_url(TELEGRAM_API_URL, token, path); let resp = client.get(&url).send().await?.error_for_status()?; Ok(resp.into_body()) -} \ No newline at end of file +} diff --git a/src/network/request.rs b/src/network/request.rs index 90e10c21..8b648b01 100644 --- a/src/network/request.rs +++ b/src/network/request.rs @@ -1,22 +1,22 @@ -use serde::{de::DeserializeOwned, Serialize}; -use reqwest::r#async::{ - Client, multipart::Form, Response, -}; use apply::Apply; +use reqwest::r#async::{multipart::Form, Client, Response}; +use serde::{de::DeserializeOwned, Serialize}; use crate::{ - RequestError, - requests::ResponseResult, network::{method_url, TELEGRAM_API_URL}, + requests::ResponseResult, + RequestError, }; - pub async fn request_multipart( client: &Client, token: &str, method_name: &str, params: Option
, -) -> ResponseResult where T: DeserializeOwned { +) -> ResponseResult +where + T: DeserializeOwned, +{ process_response( client .post(&method_url(TELEGRAM_API_URL, token, method_name)) @@ -28,7 +28,7 @@ pub async fn request_multipart( .await .map_err(RequestError::NetworkError)?, ) - .await + .await } pub async fn request_json( @@ -45,7 +45,7 @@ pub async fn request_json( .await .map_err(RequestError::NetworkError)?, ) - .await + .await } async fn process_response( @@ -54,7 +54,7 @@ async fn process_response( let response = serde_json::from_str::>( &response.text().await.map_err(RequestError::NetworkError)?, ) - .map_err(RequestError::InvalidJson)?; + .map_err(RequestError::InvalidJson)?; response.into() } diff --git a/src/requests/edit_message_live_location.rs b/src/requests/edit_message_live_location.rs index c4c3200c..9740e88c 100644 --- a/src/requests/edit_message_live_location.rs +++ b/src/requests/edit_message_live_location.rs @@ -1,6 +1,8 @@ use crate::{ network, - requests::{ChatId, Request, RequestContext, RequestFuture, ResponseResult}, + requests::{ + ChatId, Request, RequestContext, RequestFuture, ResponseResult, + }, types::{Message, ReplyMarkup}, }; diff --git a/src/requests/get_chat.rs b/src/requests/get_chat.rs index 1e839e9c..3abb09cd 100644 --- a/src/requests/get_chat.rs +++ b/src/requests/get_chat.rs @@ -1,23 +1,24 @@ use crate::{ network, + requests::{ + ChatId, Request, RequestContext, RequestFuture, ResponseResult, + }, types::Chat, - requests::{ChatId, RequestContext, RequestFuture, ResponseResult, Request}, }; -/// Use this method to get up to date information about the chat -/// (current name of the user for one-on-one conversations, -/// current username of a user, group or channel, etc.). +/// Use this method to get up to date information about the chat +/// (current name of the user for one-on-one conversations, +/// current username of a user, group or channel, etc.). /// Returns a Chat object on success. #[derive(Debug, Clone, Serialize)] pub struct GetChat<'a> { #[serde(skip_serializing)] ctx: RequestContext<'a>, - /// Unique identifier for the target chat or username + /// Unique identifier for the target chat or username /// of the target supergroup or channel (in the format @channelusername) chat_id: ChatId, } - impl<'a> Request<'a> for GetChat<'a> { type ReturnValue = Chat; @@ -28,16 +29,16 @@ impl<'a> Request<'a> for GetChat<'a> { &self.ctx.token, "getChat", &self, - ).await + ) + .await }) } } - -impl<'a> GetChat<'a>{ +impl<'a> GetChat<'a> { pub fn chat_id(mut self, chat_id: T) -> Self - where - T: Into, + where + T: Into, { self.chat_id = chat_id.into(); self diff --git a/src/requests/get_file.rs b/src/requests/get_file.rs index 6eba2aff..2f3ee638 100644 --- a/src/requests/get_file.rs +++ b/src/requests/get_file.rs @@ -4,7 +4,6 @@ use crate::{ types::File, }; - /// Use this method to get basic info about a file and prepare it for /// downloading. For the moment, bots can download files of up to 20MB in size. /// On success, a File object is returned. diff --git a/src/requests/send_audio.rs b/src/requests/send_audio.rs index 503cd653..64a2ede7 100644 --- a/src/requests/send_audio.rs +++ b/src/requests/send_audio.rs @@ -1,7 +1,8 @@ use crate::{ network, requests::{ - form_builder::FormBuilder, ChatId, Request, RequestContext, RequestFuture, ResponseResult, + form_builder::FormBuilder, ChatId, Request, RequestContext, + RequestFuture, ResponseResult, }, types::{InputFile, Message, ParseMode, ReplyMarkup}, }; diff --git a/src/requests/send_chat_action.rs b/src/requests/send_chat_action.rs index d5d5ff0b..639307cc 100644 --- a/src/requests/send_chat_action.rs +++ b/src/requests/send_chat_action.rs @@ -2,7 +2,7 @@ use crate::{ network, requests::{ ChatId, Request, RequestContext, RequestFuture, ResponseResult, - } + }, }; ///Use this method when you need to tell the user that something is happening diff --git a/src/requests/send_contact.rs b/src/requests/send_contact.rs index 537e9a09..3a0f6e30 100644 --- a/src/requests/send_contact.rs +++ b/src/requests/send_contact.rs @@ -1,10 +1,11 @@ use crate::{ network, - requests::{ChatId, Request, RequestContext, RequestFuture, ResponseResult}, + requests::{ + ChatId, Request, RequestContext, RequestFuture, ResponseResult, + }, types::{Message, ReplyMarkup}, }; - /// Use this method to send phone contacts. /// returned. #[derive(Debug, Clone, Serialize)] diff --git a/src/requests/send_media_group.rs b/src/requests/send_media_group.rs index f4b45015..fdfaef2e 100644 --- a/src/requests/send_media_group.rs +++ b/src/requests/send_media_group.rs @@ -9,7 +9,6 @@ use crate::{ types::{InputFile, InputMedia, Message}, }; - /// Use this method to send a group of photos or videos as an album. #[derive(Debug, Clone)] pub struct SendMediaGroup<'a> { diff --git a/src/requests/send_poll.rs b/src/requests/send_poll.rs index 5254b305..7cac05fe 100644 --- a/src/requests/send_poll.rs +++ b/src/requests/send_poll.rs @@ -1,10 +1,11 @@ use crate::{ network, - requests::{ChatId, Request, RequestContext, RequestFuture, ResponseResult}, + requests::{ + ChatId, Request, RequestContext, RequestFuture, ResponseResult, + }, types::{Message, ReplyMarkup}, }; - /// Use this method to send a native poll. A native poll can't be sent to a /// private chat. On success, the sent Message is returned. #[derive(Debug, Clone, Serialize)] diff --git a/src/requests/send_venue.rs b/src/requests/send_venue.rs index 9d2c8d87..08c7b3d9 100644 --- a/src/requests/send_venue.rs +++ b/src/requests/send_venue.rs @@ -1,10 +1,11 @@ use crate::{ network, - requests::{ChatId, Request, RequestContext, RequestFuture, ResponseResult}, + requests::{ + ChatId, Request, RequestContext, RequestFuture, ResponseResult, + }, types::{Message, ReplyMarkup}, }; - /// Use this method to send information about a venue. /// Message is returned. #[derive(Debug, Clone, Serialize)] diff --git a/src/types/callback_game.rs b/src/types/callback_game.rs index db173b68..d96110af 100644 --- a/src/types/callback_game.rs +++ b/src/types/callback_game.rs @@ -1,2 +1,2 @@ /// A placeholder, currently holds no information. Use [BotFather](https://t.me/botfather) to set up your game. -pub struct CallbackGame; \ No newline at end of file +pub struct CallbackGame; diff --git a/src/types/login_url.rs b/src/types/login_url.rs index 9013c7e9..86d8ea3b 100644 --- a/src/types/login_url.rs +++ b/src/types/login_url.rs @@ -7,4 +7,4 @@ pub struct LoginUrl { pub bot_username: Option, #[serde(skip_serializing_if = "Option::is_none")] pub request_write_access: Option, -} \ No newline at end of file +}