Run cargo fmt

This commit is contained in:
Waffle 2019-09-19 01:30:30 +03:00
parent 2b1ce74d94
commit fda1d37e77
52 changed files with 303 additions and 297 deletions

View file

@ -1,24 +1,15 @@
use reqwest::r#async::Client;
use crate::core::{
types::{
InputFile,
InputMedia,
},
requests::{
ChatId,
RequestContext,
get_me::GetMe,
send_message::SendMessage,
edit_message_live_location::EditMessageLiveLocation,
forward_message::ForwardMessage,
send_audio::SendAudio,
send_location::SendLocation,
send_media_group::SendMediaGroup,
send_photo::SendPhoto,
stop_message_live_location::StopMessageLiveLocation,
}
forward_message::ForwardMessage, get_me::GetMe, send_audio::SendAudio,
send_location::SendLocation, send_media_group::SendMediaGroup,
send_message::SendMessage, send_photo::SendPhoto,
stop_message_live_location::StopMessageLiveLocation, ChatId,
RequestContext,
},
types::{InputFile, InputMedia},
};
pub struct Bot {
@ -60,11 +51,7 @@ impl Bot {
C: Into<ChatId>,
T: Into<String>,
{
SendMessage::new(
self.ctx(),
chat_id.into(),
text.into(),
)
SendMessage::new(self.ctx(), chat_id.into(), text.into())
}
pub fn edit_message_live_location<Lt, Lg>(
@ -87,7 +74,7 @@ impl Bot {
&self,
chat_id: C,
from_chat_id: F,
message_id: M
message_id: M,
) -> ForwardMessage
where
C: Into<ChatId>,
@ -107,11 +94,7 @@ impl Bot {
C: Into<ChatId>,
A: Into<InputFile>,
{
SendAudio::new(
self.ctx(),
chat_id.into(),
audio.into()
)
SendAudio::new(self.ctx(), chat_id.into(), audio.into())
}
pub fn send_location<C, Lt, Lg>(
@ -136,30 +119,20 @@ impl Bot {
pub fn send_media_group<C, M>(&self, chat_id: C, media: M) -> SendMediaGroup
where
C: Into<ChatId>,
M: Into<Vec<InputMedia>>
M: Into<Vec<InputMedia>>,
{
SendMediaGroup::new(
self.ctx(),
chat_id.into(),
media.into(),
)
SendMediaGroup::new(self.ctx(), chat_id.into(), media.into())
}
pub fn send_photo<C, P>(&self, chat_id: C, photo: P) -> SendPhoto
where
C: Into<ChatId>,
P: Into<InputFile>
P: Into<InputFile>,
{
SendPhoto::new(
self.ctx(),
chat_id.into(),
photo.into(),
)
SendPhoto::new(self.ctx(), chat_id.into(), photo.into())
}
pub fn stop_message_live_location(&self) -> StopMessageLiveLocation {
StopMessageLiveLocation::new(
self.ctx()
)
StopMessageLiveLocation::new(self.ctx())
}
}

View file

@ -1,6 +1,6 @@
use crate::core::{
requests::{RequestContext, Request, RequestFuture, ResponseResult},
network
network,
requests::{Request, RequestContext, RequestFuture, ResponseResult},
};
#[derive(Debug, Serialize, Clone)]
@ -40,8 +40,9 @@ impl<'a> Request<'a> for AnswerPreCheckoutQuery<'a> {
&self.ctx.client,
&self.ctx.token,
"answerPreCheckoutQuery",
&self
).await
&self,
)
.await
})
}
}
@ -50,32 +51,35 @@ impl<'a> AnswerPreCheckoutQuery<'a> {
pub(crate) fn new(
ctx: RequestContext<'a>,
pre_checkout_query_id: String,
ok: bool
ok: bool,
) -> Self {
Self {
ctx,
pre_checkout_query_id,
ok,
error_message: None
error_message: None,
}
}
pub fn pre_checkout_query_id<T>(mut self, pre_checkout_query_id: T) -> Self
where T: Into<String>
where
T: Into<String>,
{
self.pre_checkout_query_id = pre_checkout_query_id.into();
self
}
pub fn ok<T>(mut self, ok: T) -> Self
where T: Into<bool>
where
T: Into<bool>,
{
self.ok = ok.into();
self
}
pub fn error_message<T>(mut self, error_message: T) -> Self
where T: Into<String>
where
T: Into<String>,
{
self.error_message = Some(error_message.into());
self

View file

@ -1,6 +1,8 @@
use crate::core::types::ShippingOption;
use crate::core::requests::{RequestContext, Request, RequestFuture, ResponseResult};
use crate::core::network;
use crate::core::requests::{
Request, RequestContext, RequestFuture, ResponseResult,
};
use crate::core::types::ShippingOption;
#[derive(Debug, Clone, Serialize)]
/// If you sent an invoice requesting a shipping address and the parameter
@ -40,8 +42,9 @@ impl<'a> Request<'a> for AnswerShippingQuery<'a> {
&self.ctx.client,
&self.ctx.token,
"answerShippingQuery",
&self
).await
&self,
)
.await
})
}
}
@ -50,40 +53,44 @@ impl<'a> AnswerShippingQuery<'a> {
pub(crate) fn new(
ctx: RequestContext<'a>,
shipping_query_id: String,
ok: bool
ok: bool,
) -> Self {
Self {
ctx,
shipping_query_id,
ok,
shipping_options: None,
error_message: None
error_message: None,
}
}
pub fn shipping_query_id<T>(mut self, shipping_query_id: T) -> Self
where T: Into<String>
where
T: Into<String>,
{
self.shipping_query_id = shipping_query_id.into();
self
}
pub fn ok<T>(mut self, ok: T) -> Self
where T: Into<bool>
where
T: Into<bool>,
{
self.ok = ok.into();
self
}
pub fn shipping_options<T>(mut self, shipping_options: T) -> Self
where T: Into<Vec<ShippingOption>>
where
T: Into<Vec<ShippingOption>>,
{
self.shipping_options = Some(shipping_options.into());
self
}
pub fn error_message<T>(mut self, error_message: T) -> Self
where T: Into<String>
where
T: Into<String>,
{
self.error_message = Some(error_message.into());
self

View file

@ -1,11 +1,7 @@
use crate::core::{
network,
requests::{
ChatId,
Request,
RequestFuture,
RequestContext,
ResponseResult,
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
},
types::Message,
};

View file

@ -1,9 +1,11 @@
use crate::core::requests::{RequestContext, RequestFuture, ResponseResult, Request};
use crate::core::types::File;
use crate::core::network;
use crate::core::requests::{
Request, RequestContext, RequestFuture, ResponseResult,
};
use crate::core::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.
/// 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.
/// The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>,
/// where <file_path> is taken from the response.
@ -14,10 +16,9 @@ struct GetFile<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
/// File identifier to get info about
file_id: String
file_id: String,
}
impl<'a> Request<'a> for GetFile<'a> {
type ReturnValue = File;
@ -29,16 +30,15 @@ impl<'a> Request<'a> for GetFile<'a> {
"getFile",
&self,
)
.await
.await
})
}
}
impl<'a> GetFile<'a>{
impl<'a> GetFile<'a> {
pub fn file_id<T>(mut self, file_id: T) -> Self
where
T: Into<String>,
where
T: Into<String>,
{
self.file_id = file_id.into();
self

View file

@ -1,9 +1,12 @@
use crate::core::network;
use crate::core::requests::{ChatId, Request, RequestContext, RequestFuture, ResponseResult};
use crate::core::requests::{
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
};
///Use this method when you need to tell the user that something is happening on the bot's side.
///The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).
///Returns True on success.
///Use this method when you need to tell the user that something is happening
/// on the bot's side. The status is set for 5 seconds or less (when a message
/// arrives from your bot, Telegram clients clear its typing status).
/// Returns True on success.
#[derive(Debug, Clone, Serialize)]
struct SendChatAction<'a> {
#[serde(skip_serializing)]
@ -45,7 +48,7 @@ impl<'a> Request<'a> for SendChatAction<'a> {
"sendChatAction",
&self,
)
.await
.await
})
}
}
@ -64,19 +67,18 @@ impl<'a> SendChatAction<'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
}
pub fn action<T>(mut self, action: T) -> Self
where
T: Into<ChatAction>,
where
T: Into<ChatAction>,
{
self.action = action.into();
self
}
}
}

View file

@ -1,11 +1,7 @@
use crate::core::{
network,
requests::{
ChatId,
Request,
RequestFuture,
RequestContext,
ResponseResult,
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
},
types::{Message, ParseMode, ReplyMarkup},
};

View file

@ -1,11 +1,7 @@
use crate::core::{
network,
requests::{
ChatId,
Request,
RequestFuture,
RequestContext,
ResponseResult,
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
},
types::{InlineKeyboardMarkup, Message},
};

View file

@ -2,11 +2,7 @@ use std::path::PathBuf;
use bytes::{Bytes, BytesMut};
use reqwest::r#async::multipart::Part;
use tokio::{
prelude::*,
codec::FramedRead,
};
use tokio::{codec::FramedRead, prelude::*};
struct FileDecoder;

View file

@ -19,7 +19,7 @@ pub struct Animation {
/// Optional. MIME type of the file as defined by sender
pub mime_type: Option<String>,
/// Optional. File size
pub file_size: Option<u32>
pub file_size: Option<u32>,
}
#[cfg(test)]
@ -51,11 +51,11 @@ mod tests {
file_id: "id".to_string(),
width: 320,
height: 320,
file_size: Some(3452)
file_size: Some(3452),
}),
file_name: Some("some".to_string()),
mime_type: Some("gif".to_string()),
file_size: Some(6500)
file_size: Some(6500),
};
let actual = serde_json::from_str::<Animation>(json).unwrap();
assert_eq!(actual, expected)

View file

@ -1,6 +1,7 @@
use crate::core::types::{User, Message};
use crate::core::types::{Message, User};
/// This object represents an incoming callback query from a callback button in an inline keyboard.
/// This object represents an incoming callback query from a callback button in
/// an inline keyboard.
#[derive(Debug, Deserialize, PartialEq, Clone)]
pub struct CallbackQuery {
/// Unique identifier for this query
@ -8,12 +9,14 @@ pub struct CallbackQuery {
/// Sender
pub from: User,
/// Message with the callback button that originated the query.
/// Note that message content and message date will not be available if the message is too old
/// Note that message content and message date will not be available if the
/// message is too old
pub message: Message,
/// Global identifier, uniquely corresponding to the chat to which the message
/// with the callback button was sent. Useful for high scores in games.
/// Global identifier, uniquely corresponding to the chat to which the
/// message with the callback button was sent. Useful for high scores
/// in games.
pub chat_instance: String,
/// Data associated with the callback button. Be aware that a bad client can
/// send arbitrary data in this field.
/// Data associated with the callback button. Be aware that a bad client
/// can send arbitrary data in this field.
pub data: String,
}
}

View file

@ -1,6 +1,5 @@
use crate::core::types::{ChatPermissions, ChatPhoto, Message};
#[derive(Debug, Deserialize, PartialEq, Clone)]
pub struct Chat {
pub id: i64,
@ -9,7 +8,6 @@ pub struct Chat {
pub photo: Option<ChatPhoto>,
}
#[derive(Debug, Deserialize, PartialEq, Clone)]
#[serde(untagged)]
pub enum ChatKind {

View file

@ -1,4 +1,4 @@
use crate::core::types::{User, Location};
use crate::core::types::{Location, User};
#[derive(Debug, Deserialize, Clone, PartialEq)]
/// Represents a result of an inline query that was chosen by the user and
@ -11,9 +11,9 @@ pub struct ChosenInlineResult {
pub from: User,
/// Optional. Sender location, only for bots that require user location
pub location: Option<Location>,
/// Optional. Identifier of the sent inline message. Available only if there is an inline
/// keyboard attached to the message. Will be also received in callback queries and can
/// be used to edit the message.
/// Optional. Identifier of the sent inline message. Available only if
/// there is an inline keyboard attached to the message. Will be also
/// received in callback queries and can be used to edit the message.
pub inline_message_id: Option<String>,
/// The query that was used to obtain the result
pub query: String,

View file

@ -12,4 +12,4 @@ pub struct Contact {
/// Optional. Additional data about the contact in the form of a
/// [vCard](https://en.wikipedia.org/wiki/VCard)
pub vcard: Option<String>,
}
}

View file

@ -2,5 +2,5 @@
pub struct File {
pub file_id: String,
pub file_size: u32,
pub file_path: String
pub file_path: String,
}

View file

@ -1,10 +1,10 @@
use serde::Deserialize;
use crate::core::types::{MessageEntity, PhotoSize, Animation};
use crate::core::types::{Animation, MessageEntity, PhotoSize};
#[derive(Debug, Deserialize, Clone, PartialEq, Eq, Hash)]
/// This object represents a game. Use BotFather to create and edit games, their short names
/// will act as unique identifiers.
/// This object represents a game. Use BotFather to create and edit games, their
/// short names will act as unique identifiers.
pub struct Game {
/// Title of the game
pub title: String,
@ -12,13 +12,15 @@ pub struct Game {
pub description: String,
/// Photo that will be displayed in the game message in chats.
pub photo: Vec<PhotoSize>,
/// Optional. Brief description of the game or high scores included in the game message.
/// Can be automatically edited to include current high scores for the game when
/// the bot calls setGameScore, or manually edited using editMessageText. 0-4096 characters.
/// Optional. Brief description of the game or high scores included in the
/// game message. Can be automatically edited to include current high
/// scores for the game when the bot calls setGameScore, or manually
/// edited using editMessageText. 0-4096 characters.
pub text: Option<String>,
/// Optional. Special entities that appear in text, such as usernames, URLs, bot commands, etc.
/// Optional. Special entities that appear in text, such as usernames,
/// URLs, bot commands, etc.
pub text_entities: Option<Vec<MessageEntity>>,
/// Optional. Animation that will be displayed in the game message in chats.
/// Upload via BotFather
/// Optional. Animation that will be displayed in the game message in
/// chats. Upload via BotFather
pub animation: Option<Animation>,
}
}

View file

@ -62,32 +62,37 @@ impl InlineKeyboardButton {
}
}
pub fn callback(text: String, callback_data: String)
-> InlineKeyboardButton {
pub fn callback(
text: String,
callback_data: String,
) -> InlineKeyboardButton {
InlineKeyboardButton {
text,
kind: InlineKeyboardButtonKind::CallbackData(callback_data),
}
}
pub fn switch_inline_query(text: String, switch_inline_query: String)
-> InlineKeyboardButton {
pub fn switch_inline_query(
text: String,
switch_inline_query: String,
) -> InlineKeyboardButton {
InlineKeyboardButton {
text,
kind: InlineKeyboardButtonKind::SwitchInlineQuery(switch_inline_query)
kind: InlineKeyboardButtonKind::SwitchInlineQuery(
switch_inline_query,
),
}
}
pub fn switch_inline_query_current_chat(
text: String,
switch_inline_query_current_chat: String
switch_inline_query_current_chat: String,
) -> InlineKeyboardButton {
InlineKeyboardButton {
text,
kind: InlineKeyboardButtonKind::SwitchInlineQueryCurrentChat(
switch_inline_query_current_chat
)
switch_inline_query_current_chat,
),
}
}
}

View file

@ -17,22 +17,19 @@ pub struct InlineKeyboardMarkup {
/// Example:
/// ```
/// use async_telegram_bot::core::types::{
/// InlineKeyboardMarkup,
/// InlineKeyboardButton
/// InlineKeyboardButton, InlineKeyboardMarkup,
/// };
///
///
/// let url_button = InlineKeyboardButton::url(
/// "text".to_string(),
/// "http://url.com".to_string()
/// "http://url.com".to_string(),
/// );
/// let keyboard = InlineKeyboardMarkup::new()
/// .append_row(vec![url_button]);
/// let keyboard = InlineKeyboardMarkup::new().append_row(vec![url_button]);
/// ```
impl InlineKeyboardMarkup {
pub fn new() -> Self {
Self {
inline_keyboard: vec![]
inline_keyboard: vec![],
}
}
@ -41,11 +38,14 @@ impl InlineKeyboardMarkup {
self
}
pub fn append_to_row(mut self, button: InlineKeyboardButton, index: usize)
-> Self {
pub fn append_to_row(
mut self,
button: InlineKeyboardButton,
index: usize,
) -> Self {
match self.inline_keyboard.get_mut(index) {
Some(buttons) => buttons.push(button),
None => self.inline_keyboard.push(vec![button])
None => self.inline_keyboard.push(vec![button]),
};
self
}
@ -68,9 +68,7 @@ mod tests {
let markup = InlineKeyboardMarkup::new()
.append_row(vec![button1.clone(), button2.clone()]);
let expected = InlineKeyboardMarkup {
inline_keyboard: vec![
vec![button1.clone(), button2.clone()]
]
inline_keyboard: vec![vec![button1.clone(), button2.clone()]],
};
assert_eq!(markup, expected);
}
@ -89,9 +87,7 @@ mod tests {
.append_row(vec![button1.clone()])
.append_to_row(button2.clone(), 0);
let expected = InlineKeyboardMarkup {
inline_keyboard: vec![
vec![button1.clone(), button2.clone()]
]
inline_keyboard: vec![vec![button1.clone(), button2.clone()]],
};
assert_eq!(markup, expected);
}
@ -110,10 +106,7 @@ mod tests {
.append_row(vec![button1.clone()])
.append_to_row(button2.clone(), 1);
let expected = InlineKeyboardMarkup {
inline_keyboard: vec![
vec![button1.clone()],
vec![button2.clone()]
]
inline_keyboard: vec![vec![button1.clone()], vec![button2.clone()]],
};
assert_eq!(markup, expected);
}

View file

@ -1,4 +1,4 @@
use crate::core::types::{User, Location};
use crate::core::types::{Location, User};
#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQuery {

View file

@ -1,26 +1,16 @@
use crate::core::types::{
InlineQueryResultCachedAudio,
InlineQueryResultCachedDocument,
InlineQueryResultCachedGif,
InlineQueryResultCachedMpeg4Gif,
InlineQueryResultCachedPhoto,
InlineQueryResultCachedSticker,
InlineQueryResultCachedVideo,
InlineQueryResultCachedVoice,
InlineQueryResultArticle,
InlineQueryResultAudio,
InlineQueryResultContact,
InlineQueryResultGame,
InlineQueryResultDocument,
InlineQueryResultGif,
InlineQueryResultLocation,
InlineQueryResultMpeg4Gif,
InlineQueryResultPhoto,
InlineQueryResultVenue,
InlineQueryResultVideo,
InlineQueryResultVoice
InlineQueryResultArticle, InlineQueryResultAudio,
InlineQueryResultCachedAudio, InlineQueryResultCachedDocument,
InlineQueryResultCachedGif, InlineQueryResultCachedMpeg4Gif,
InlineQueryResultCachedPhoto, InlineQueryResultCachedSticker,
InlineQueryResultCachedVideo, InlineQueryResultCachedVoice,
InlineQueryResultContact, InlineQueryResultDocument, InlineQueryResultGame,
InlineQueryResultGif, InlineQueryResultLocation, InlineQueryResultMpeg4Gif,
InlineQueryResultPhoto, InlineQueryResultVenue, InlineQueryResultVideo,
InlineQueryResultVoice,
};
/// This object represents one result of an inline query.
#[derive(Debug, Serialize, PartialEq, Clone)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
@ -59,24 +49,26 @@ pub enum InlineQueryResult {
#[cfg(test)]
mod tests {
use crate::core::types::{InlineQueryResult, InlineQueryResultCachedAudio, InputMessageContent};
use crate::core::types::parse_mode::ParseMode;
use crate::core::types::inline_keyboard_markup::InlineKeyboardMarkup;
use crate::core::types::parse_mode::ParseMode;
use crate::core::types::{
InlineQueryResult, InlineQueryResultCachedAudio, InputMessageContent,
};
#[test]
fn cached_audio_min_serialize() {
let structure = InlineQueryResult::CachedAudio(
InlineQueryResultCachedAudio {
let structure =
InlineQueryResult::CachedAudio(InlineQueryResultCachedAudio {
id: String::from("id"),
audio_file_id: String::from("audio_file_id"),
caption: None,
parse_mode: None,
reply_markup: None,
input_message_content: None
}
);
input_message_content: None,
});
let expected_json = r#"{"type":"audio","id":"id","audio_file_id":"audio_file_id"}"#;
let expected_json =
r#"{"type":"audio","id":"id","audio_file_id":"audio_file_id"}"#;
let actual_json = serde_json::to_string(&structure).unwrap();
assert_eq!(expected_json, actual_json);
@ -84,8 +76,8 @@ mod tests {
#[test]
fn cached_audio_full_serialize() {
let structure = InlineQueryResult::CachedAudio(
InlineQueryResultCachedAudio {
let structure =
InlineQueryResult::CachedAudio(InlineQueryResultCachedAudio {
id: String::from("id"),
audio_file_id: String::from("audio_file_id"),
caption: Some(String::from("caption")),
@ -94,10 +86,9 @@ mod tests {
input_message_content: Some(InputMessageContent::Text {
message_text: String::from("message_text"),
parse_mode: Some(ParseMode::Markdown),
disable_web_page_preview: Some(true)
})
}
);
disable_web_page_preview: Some(true),
}),
});
let expected_json = r#"{"type":"audio","id":"id","audio_file_id":"audio_file_id","caption":"caption","parse_mode":"HTML","reply_markup":{"inline_keyboard":[]},"input_message_content":{"message_text":"message_text","parse_mode":"Markdown","disable_web_page_preview":true}}"#;
let actual_json = serde_json::to_string(&structure).unwrap();
@ -106,4 +97,4 @@ mod tests {
}
// TODO: Add more tests
}
}

View file

@ -1,4 +1,4 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup};
use crate::core::types::{InlineKeyboardMarkup, InputMessageContent};
#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultArticle {
@ -14,7 +14,8 @@ pub struct InlineQueryResultArticle {
/// Optional. URL of the result
#[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
/// Optional. Pass True, if you don't want the URL to be shown in the message
/// Optional. Pass True, if you don't want the URL to be shown in the
/// message
#[serde(skip_serializing_if = "Option::is_none")]
pub hide_url: Option<bool>,
/// Optional. Short description of the result

View file

@ -1,4 +1,6 @@
use crate::core::types::{ParseMode, InlineKeyboardMarkup, InputMessageContent};
use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultAudio {
@ -17,4 +19,4 @@ pub struct InlineQueryResultAudio {
pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
}
}

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode};
use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultCachedAudio {
@ -12,4 +14,4 @@ pub struct InlineQueryResultCachedAudio {
pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
}
}

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode};
use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultCachedDocument {
@ -15,4 +17,4 @@ pub struct InlineQueryResultCachedDocument {
pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
}
}

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode};
use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultCachedGif {
@ -14,4 +16,4 @@ pub struct InlineQueryResultCachedGif {
pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
}
}

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode};
use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultCachedMpeg4Gif {
@ -14,4 +16,4 @@ pub struct InlineQueryResultCachedMpeg4Gif {
pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
}
}

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode};
use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultCachedPhoto {
@ -16,4 +18,4 @@ pub struct InlineQueryResultCachedPhoto {
pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
}
}

View file

@ -1,4 +1,4 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup};
use crate::core::types::{InlineKeyboardMarkup, InputMessageContent};
#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultCachedSticker {
@ -8,4 +8,4 @@ pub struct InlineQueryResultCachedSticker {
pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
}
}

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode};
use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultCachedVideo {
@ -15,4 +17,4 @@ pub struct InlineQueryResultCachedVideo {
pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
}
}

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode};
use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultCachedVoice {
@ -13,4 +15,4 @@ pub struct InlineQueryResultCachedVoice {
pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
}
}

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode};
use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultContact {
@ -19,4 +21,4 @@ pub struct InlineQueryResultContact {
pub thumb_width: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub thumb_height: Option<i32>,
}
}

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode};
use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultDocument {
@ -22,4 +24,4 @@ pub struct InlineQueryResultDocument {
pub thumb_width: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub thumb_height: Option<i32>,
}
}

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode};
use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, Hash, PartialEq, Eq, Clone)]
pub struct InlineQueryResultGame {
@ -6,4 +8,4 @@ pub struct InlineQueryResultGame {
pub game_short_name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<InlineKeyboardMarkup>,
}
}

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode};
use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultGif {
@ -21,4 +23,4 @@ pub struct InlineQueryResultGif {
pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
}
}

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode};
use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultLocation {
@ -18,4 +20,4 @@ pub struct InlineQueryResultLocation {
pub thumb_width: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub thumb_height: Option<i32>,
}
}

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode};
use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultMpeg4Gif {
@ -21,4 +23,4 @@ pub struct InlineQueryResultMpeg4Gif {
pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
}
}

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode};
use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultPhoto {
@ -21,4 +23,4 @@ pub struct InlineQueryResultPhoto {
pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
}
}

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode};
use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultVenue {
@ -21,4 +23,4 @@ pub struct InlineQueryResultVenue {
pub thumb_width: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub thumb_height: Option<i32>,
}
}

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode};
use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultVideo {
@ -23,4 +25,4 @@ pub struct InlineQueryResultVideo {
pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
}
}

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode};
use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultVoice {
@ -15,4 +17,4 @@ pub struct InlineQueryResultVoice {
pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>,
}
}

View file

@ -8,18 +8,20 @@ use crate::core::types::ParseMode;
/// a result of an inline query.
/// [More](https://core.telegram.org/bots/api#inputmessagecontent)
pub enum InputMessageContent {
/// Represents the content of a text message to be sent as the result of an inline query.
/// Represents the content of a text message to be sent as the result of an
/// inline query.
Text {
/// 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.
/// if you want Telegram apps to show [bold, italic, fixed-width text
/// or inline URLs] in the media caption.
///
/// [Markdown]: crate::core::types::ParseMode::Markdown
/// [Html]: crate::core::types::ParseMode::Html
/// [bold, italic, fixed-width text or inline URLs]: crate::core::types::ParseMode
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::core::types::ParseMode
#[serde(skip_serializing_if = "Option::is_none")]
parse_mode: Option<ParseMode>,
@ -27,18 +29,21 @@ pub enum InputMessageContent {
#[serde(skip_serializing_if = "Option::is_none")]
disable_web_page_preview: Option<bool>,
},
/// Represents the content of a location message to be sent as the result of an inline query.
/// Represents the content of a location message to be sent as the result
/// of an inline query.
Location {
/// Latitude of the location in degrees
latitude: f64,
/// Longitude of the location in degrees
longitude: f64,
/// Period in seconds for which the location can be updated, should be between 60 and 86400.
/// Period in seconds for which the location can be updated, should be
/// between 60 and 86400.
#[serde(skip_serializing_if = "Option::is_none")]
live_period: Option<u32>,
},
/// Represents the content of a venue message to be sent as the result of an inline query.
/// Represents the content of a venue message to be sent as the result of
/// an inline query.
Venue {
/// Latitude of the venue in degrees
latitude: f64,
@ -53,12 +58,14 @@ pub enum InputMessageContent {
#[serde(skip_serializing_if = "Option::is_none")]
foursquare_id: Option<String>,
/// Foursquare type of the venue, if known. (For example, “arts_entertainment/default”,
/// “arts_entertainment/aquarium” or “food/icecream”.)
/// Foursquare type of the venue, if known. (For example,
/// “arts_entertainment/default”, “arts_entertainment/aquarium”
/// or “food/icecream”.)
#[serde(skip_serializing_if = "Option::is_none")]
foursquare_type: Option<String>,
},
/// Represents the content of a contact message to be sent as the result of an inline query.
/// Represents the content of a contact message to be sent as the result of
/// an inline query.
Contact {
/// Contact's phone number
phone_number: String,
@ -124,7 +131,8 @@ mod tests {
#[test]
fn contact_serialize() {
let expected_json = r#"{"phone_number":"+3800000000","first_name":"jhon"}"#;
let expected_json =
r#"{"phone_number":"+3800000000","first_name":"jhon"}"#;
let contact_content = InputMessageContent::Contact {
phone_number: String::from("+3800000000"),
first_name: String::from("jhon"),
@ -135,4 +143,4 @@ mod tests {
let actual_json = serde_json::to_string(&contact_content).unwrap();
assert_eq!(expected_json, actual_json);
}
}
}

View file

@ -20,7 +20,7 @@ mod tests {
fn serialize() {
let labeled_price = LabeledPrice {
label: "Label".to_string(),
amount: 60
amount: 60,
};
let expected = r#"{"label":"Label","amount":60}"#;
let actual = serde_json::to_string(&labeled_price).unwrap();

View file

@ -5,4 +5,4 @@ pub struct Location {
pub longitude: f64,
/// Latitude as defined by sender
pub latitude: f64,
}
}

View file

@ -5,4 +5,3 @@ pub struct MaskPosition {
pub y_shift: f64,
pub scale: f64,
}

View file

@ -10,12 +10,36 @@ pub use self::{
chosen_inline_result::ChosenInlineResult,
contact::Contact,
document::Document,
file::File,
force_reply::ForceReply,
game::Game,
inline_keyboard_button::{InlineKeyboardButton, InlineKeyboardButtonKind},
inline_keyboard_markup::InlineKeyboardMarkup,
inline_query::InlineQuery,
inline_query_result::InlineQueryResult,
inline_query_result_article::InlineQueryResultArticle,
inline_query_result_audio::InlineQueryResultAudio,
inline_query_result_cached_audio::InlineQueryResultCachedAudio,
inline_query_result_cached_document::InlineQueryResultCachedDocument,
inline_query_result_cached_gif::InlineQueryResultCachedGif,
inline_query_result_cached_mpeg4_gif::InlineQueryResultCachedMpeg4Gif,
inline_query_result_cached_photo::InlineQueryResultCachedPhoto,
inline_query_result_cached_sticker::InlineQueryResultCachedSticker,
inline_query_result_cached_video::InlineQueryResultCachedVideo,
inline_query_result_cached_voice::InlineQueryResultCachedVoice,
inline_query_result_contact::InlineQueryResultContact,
inline_query_result_document::InlineQueryResultDocument,
inline_query_result_game::InlineQueryResultGame,
inline_query_result_gif::InlineQueryResultGif,
inline_query_result_location::InlineQueryResultLocation,
inline_query_result_mpeg4_gif::InlineQueryResultMpeg4Gif,
inline_query_result_photo::InlineQueryResultPhoto,
inline_query_result_venue::InlineQueryResultVenue,
inline_query_result_video::InlineQueryResultVideo,
inline_query_result_voice::InlineQueryResultVoice,
input_file::InputFile,
input_media::InputMedia,
input_message_content::InputMessageContent,
invoice::Invoice,
keyboard_button::KeyboardButton,
label_price::LabeledPrice,
@ -46,31 +70,6 @@ pub use self::{
video::Video,
video_note::VideoNote,
voice::Voice,
file::File,
input_message_content::InputMessageContent,
inline_query::InlineQuery,
inline_query_result::InlineQueryResult,
inline_query_result_cached_audio::InlineQueryResultCachedAudio,
inline_query_result_cached_document::InlineQueryResultCachedDocument,
inline_query_result_cached_gif::InlineQueryResultCachedGif,
inline_query_result_cached_mpeg4_gif::InlineQueryResultCachedMpeg4Gif,
inline_query_result_cached_photo::InlineQueryResultCachedPhoto,
inline_query_result_cached_sticker::InlineQueryResultCachedSticker,
inline_query_result_cached_video::InlineQueryResultCachedVideo,
inline_query_result_cached_voice::InlineQueryResultCachedVoice,
inline_query_result_article::InlineQueryResultArticle,
inline_query_result_audio::InlineQueryResultAudio,
inline_query_result_contact::InlineQueryResultContact,
inline_query_result_game::InlineQueryResultGame,
inline_query_result_document::InlineQueryResultDocument,
inline_query_result_gif::InlineQueryResultGif,
inline_query_result_location::InlineQueryResultLocation,
inline_query_result_mpeg4_gif::InlineQueryResultMpeg4Gif,
inline_query_result_photo::InlineQueryResultPhoto,
inline_query_result_venue::InlineQueryResultVenue,
inline_query_result_video::InlineQueryResultVideo,
inline_query_result_voice::InlineQueryResultVoice,
};
mod animation;
@ -83,12 +82,14 @@ mod chat_photo;
mod chosen_inline_result;
mod contact;
mod document;
mod file;
mod force_reply;
mod game;
mod inline_keyboard_button;
mod inline_keyboard_markup;
mod input_file;
mod input_media;
mod input_message_content;
mod invoice;
mod keyboard_button;
mod label_price;
@ -118,11 +119,11 @@ mod venue;
mod video;
mod video_note;
mod voice;
mod file;
mod input_message_content;
mod inline_query;
mod inline_query_result;
mod inline_query_result_article;
mod inline_query_result_audio;
mod inline_query_result_cached_audio;
mod inline_query_result_cached_document;
mod inline_query_result_cached_gif;
@ -131,11 +132,9 @@ mod inline_query_result_cached_photo;
mod inline_query_result_cached_sticker;
mod inline_query_result_cached_video;
mod inline_query_result_cached_voice;
mod inline_query_result_article;
mod inline_query_result_audio;
mod inline_query_result_contact;
mod inline_query_result_game;
mod inline_query_result_document;
mod inline_query_result_game;
mod inline_query_result_gif;
mod inline_query_result_location;
mod inline_query_result_mpeg4_gif;

View file

@ -24,7 +24,7 @@ mod tests {
file_id: "id".to_string(),
width: 320,
height: 320,
file_size: Some(3452)
file_size: Some(3452),
};
let actual = serde_json::from_str::<PhotoSize>(json).unwrap();
assert_eq!(actual, expected);

View file

@ -1,5 +1,5 @@
use crate::core::types::{InlineKeyboardMarkup, LabeledPrice};
use crate::core::requests::ChatId;
use crate::core::types::{InlineKeyboardMarkup, LabeledPrice};
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct SendInvoice {

View file

@ -20,9 +20,10 @@ mod tests {
let shipping_option = ShippingOption {
id: "0".to_string(),
title: "Option".to_string(),
prices: vec![
LabeledPrice { label: "Label".to_string(), amount: 60 }
]
prices: vec![LabeledPrice {
label: "Label".to_string(),
amount: 60,
}],
};
let expected = r#"{"id":"0","title":"Option","prices":[{"label":"Label","amount":60}]}"#;
let actual = serde_json::to_string(&shipping_option).unwrap();

View file

@ -1,6 +1,4 @@
use crate::core::types::{
Message, ChosenInlineResult, CallbackQuery,
};
use crate::core::types::{CallbackQuery, ChosenInlineResult, Message};
#[derive(Debug, Deserialize, PartialEq, Clone)]
pub struct Update {

View file

@ -1,6 +1,5 @@
use crate::core::types::Location;
/// This object represents a venue.
#[derive(Debug, Deserialize, PartialEq, Serialize, Clone)]
pub struct Venue {
@ -13,7 +12,9 @@ pub struct Venue {
/// Foursquare identifier of the venue
#[serde(skip_serializing_if = "Option::is_none")]
pub foursquare_id: Option<String>,
/// Foursquare type of the venue. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.)
/// Foursquare type of the venue. (For example,
/// “arts_entertainment/default”, “arts_entertainment/aquarium” or
/// “food/icecream”.)
#[serde(skip_serializing_if = "Option::is_none")]
pub foursquare_type: Option<String>, // TODO: is this enum?...
}
}

View file

@ -1,5 +1,5 @@
use serde::Deserialize;
use crate::core::types::PhotoSize;
use serde::Deserialize;
#[derive(Debug, Deserialize, Clone, PartialEq, Eq, Hash)]
/// This object represents a [video message](https://telegram.org/blog/video-messages-and-telescope)
@ -7,7 +7,8 @@ use crate::core::types::PhotoSize;
pub struct VideoNote {
/// Identifier for this file
pub file_id: String,
/// Video width and height (diameter of the video message) as defined by sender
/// Video width and height (diameter of the video message) as defined by
/// sender
pub length: u32,
/// Duration of the video in seconds as defined by sender
pub duration: u32,
@ -15,4 +16,4 @@ pub struct VideoNote {
pub thumb: Option<PhotoSize>,
/// Optional. File size
pub file_size: Option<u32>,
}
}

View file

@ -11,4 +11,4 @@ pub struct Voice {
pub mime_type: Option<String>,
/// Optional. File size
pub file_size: Option<u64>,
}
}