cargo fmt

This commit is contained in:
Waffle 2019-09-21 00:57:17 +03:00
parent f37552536e
commit f95ea5ee31
14 changed files with 48 additions and 49 deletions

View file

@ -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.

View file

@ -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<D>(
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())
}
}

View file

@ -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<T>(
client: &Client,
token: &str,
method_name: &str,
params: Option<Form>,
) -> ResponseResult<T> where T: DeserializeOwned {
) -> ResponseResult<T>
where
T: DeserializeOwned,
{
process_response(
client
.post(&method_url(TELEGRAM_API_URL, token, method_name))
@ -28,7 +28,7 @@ pub async fn request_multipart<T>(
.await
.map_err(RequestError::NetworkError)?,
)
.await
.await
}
pub async fn request_json<T: DeserializeOwned, P: Serialize>(
@ -45,7 +45,7 @@ pub async fn request_json<T: DeserializeOwned, P: Serialize>(
.await
.map_err(RequestError::NetworkError)?,
)
.await
.await
}
async fn process_response<T: DeserializeOwned>(
@ -54,7 +54,7 @@ async fn process_response<T: DeserializeOwned>(
let response = serde_json::from_str::<TelegramResponse<T>>(
&response.text().await.map_err(RequestError::NetworkError)?,
)
.map_err(RequestError::InvalidJson)?;
.map_err(RequestError::InvalidJson)?;
response.into()
}

View file

@ -1,6 +1,8 @@
use crate::{
network,
requests::{ChatId, Request, RequestContext, RequestFuture, ResponseResult},
requests::{
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
},
types::{Message, ReplyMarkup},
};

View file

@ -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<T>(mut self, chat_id: T) -> Self
where
T: Into<ChatId>,
where
T: Into<ChatId>,
{
self.chat_id = chat_id.into();
self

View file

@ -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.

View file

@ -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},
};

View file

@ -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

View file

@ -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)]

View file

@ -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> {

View file

@ -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)]

View file

@ -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)]

View file

@ -1,2 +1,2 @@
/// A placeholder, currently holds no information. Use [BotFather](https://t.me/botfather) to set up your game.
pub struct CallbackGame;
pub struct CallbackGame;

View file

@ -7,4 +7,4 @@ pub struct LoginUrl {
pub bot_username: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub request_write_access: Option<bool>,
}
}