From 59f419f947bce2fcc73383e3fb350812ef9b6684 Mon Sep 17 00:00:00 2001 From: Waffle Date: Thu, 19 Sep 2019 00:16:44 +0300 Subject: [PATCH] Clean `InlineQueryResult*` structs --- src/core/types/inline_query.rs | 2 +- src/core/types/inline_query_result.rs | 37 ++++++++++++++++++- src/core/types/inline_query_result_article.rs | 6 +-- src/core/types/inline_query_result_audio.rs | 6 +-- .../types/inline_query_result_cached_audio.rs | 7 +--- .../inline_query_result_cached_document.rs | 7 +--- .../types/inline_query_result_cached_gif.rs | 5 +-- .../inline_query_result_cached_mpeg4_gif.rs | 7 +--- .../types/inline_query_result_cached_photo.rs | 6 +-- .../inline_query_result_cached_sticker.rs | 7 +--- .../types/inline_query_result_cached_video.rs | 7 +--- .../types/inline_query_result_cached_voice.rs | 7 +--- src/core/types/inline_query_result_contact.rs | 6 +-- .../types/inline_query_result_document.rs | 5 +-- src/core/types/inline_query_result_game.rs | 6 +-- src/core/types/inline_query_result_gif.rs | 7 +--- .../types/inline_query_result_location.rs | 6 +-- .../types/inline_query_result_mpeg4_gif.rs | 7 +--- src/core/types/inline_query_result_photo.rs | 7 +--- src/core/types/inline_query_result_venue.rs | 6 +-- src/core/types/inline_query_result_video.rs | 7 +--- src/core/types/inline_query_result_voice.rs | 5 +-- src/core/types/input_message_content.rs | 2 +- src/core/types/mod.rs | 3 ++ 24 files changed, 79 insertions(+), 92 deletions(-) diff --git a/src/core/types/inline_query.rs b/src/core/types/inline_query.rs index 4ee13687..7a1fa571 100644 --- a/src/core/types/inline_query.rs +++ b/src/core/types/inline_query.rs @@ -1,6 +1,6 @@ use crate::core::types::{User, Location}; -#[derive(Debug, Serialize, Hash, PartialEq, Eq, Clone)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQuery { /// Unique identifier for this query pub id: String, diff --git a/src/core/types/inline_query_result.rs b/src/core/types/inline_query_result.rs index 99be2d4b..c4c57e29 100644 --- a/src/core/types/inline_query_result.rs +++ b/src/core/types/inline_query_result.rs @@ -1,15 +1,47 @@ -use super::inline_query_result_cached_audio::InlineQueryResultCachedAudio; +use crate::core::types::{ + InlineQueryResultCachedAudio, + InlineQueryResultCachedDocument, + InlineQueryResultCachedGif, + InlineQueryResultCachedMpeg4Gif, + InlineQueryResultCachedPhoto, + InlineQueryResultCachedSticker, + InlineQueryResultCachedVideo, + InlineQueryResultCachedVoice, + InlineQueryResultArticle, + InlineQueryResultAudio, + InlineQueryResultContact, + InlineQueryResultGame, + InlineQueryResultDocument, + InlineQueryResultGif, + InlineQueryResultLocation, + InlineQueryResultMpeg4Gif, + InlineQueryResultPhoto, + InlineQueryResultVenue, + InlineQueryResultVideo, + InlineQueryResultVoice +}; -#[derive(Debug, Deserialize, Serialize, Eq, Clone, PartialEq, Hash)] +#[derive(Debug, Serialize, PartialEq, Clone)] +#[serde(tag = "type")] +#[serde(rename_all = "snake_case")] pub enum InlineQueryResult { + #[serde(rename = "audio")] CachedAudio(InlineQueryResultCachedAudio), + #[serde(rename = "document")] CachedDocument(InlineQueryResultCachedDocument), + #[serde(rename = "gif")] CachedGif(InlineQueryResultCachedGif), + #[serde(rename = "mpeg4_gif")] CachedMpeg4Gif(InlineQueryResultCachedMpeg4Gif), + #[serde(rename = "photo")] CachedPhoto(InlineQueryResultCachedPhoto), + #[serde(rename = "sticker")] CachedSticker(InlineQueryResultCachedSticker), + #[serde(rename = "video")] CachedVideo(InlineQueryResultCachedVideo), + #[serde(rename = "voice")] CachedVoice(InlineQueryResultCachedVoice), + Article(InlineQueryResultArticle), Audio(InlineQueryResultAudio), Contact(InlineQueryResultContact), @@ -17,6 +49,7 @@ pub enum InlineQueryResult { Document(InlineQueryResultDocument), Gif(InlineQueryResultGif), Location(InlineQueryResultLocation), + #[serde(rename = "mpeg4_gif")] Mpeg4Gif(InlineQueryResultMpeg4Gif), Photo(InlineQueryResultPhoto), Venue(InlineQueryResultVenue), diff --git a/src/core/types/inline_query_result_article.rs b/src/core/types/inline_query_result_article.rs index fb31e06c..4020ac1f 100644 --- a/src/core/types/inline_query_result_article.rs +++ b/src/core/types/inline_query_result_article.rs @@ -1,11 +1,7 @@ use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Serialize, Hash, PartialEq, Eq, Clone)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultArticle { - // Type of the result, must be article - #[serde(rename = "type")] - pub query_type: String, - /// Unique identifier for this result, 1-64 Bytes pub id: String, /// Title of the result diff --git a/src/core/types/inline_query_result_audio.rs b/src/core/types/inline_query_result_audio.rs index 119184fc..e0b22e62 100644 --- a/src/core/types/inline_query_result_audio.rs +++ b/src/core/types/inline_query_result_audio.rs @@ -1,8 +1,6 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; -use crate::core::types::parse_mode::ParseMode; +use crate::core::types::{ParseMode, InlineKeyboardMarkup, InputMessageContent}; -#[derive(Debug, Serialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultAudio { pub id: String, pub audio_url: String, diff --git a/src/core/types/inline_query_result_cached_audio.rs b/src/core/types/inline_query_result_cached_audio.rs index 00266a66..80bb5022 100644 --- a/src/core/types/inline_query_result_cached_audio.rs +++ b/src/core/types/inline_query_result_cached_audio.rs @@ -1,10 +1,7 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedAudio { - #[serde(rename = "type")] - pub query_type: String, pub id: String, pub audio_file_id: String, pub caption: Option, diff --git a/src/core/types/inline_query_result_cached_document.rs b/src/core/types/inline_query_result_cached_document.rs index b26f973d..624cbee7 100644 --- a/src/core/types/inline_query_result_cached_document.rs +++ b/src/core/types/inline_query_result_cached_document.rs @@ -1,10 +1,7 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedDocument { - #[serde(rename = "type")] - pub query_type: String, pub id: String, pub title: String, pub document_file_id: String, diff --git a/src/core/types/inline_query_result_cached_gif.rs b/src/core/types/inline_query_result_cached_gif.rs index 4b083bfd..d8604013 100644 --- a/src/core/types/inline_query_result_cached_gif.rs +++ b/src/core/types/inline_query_result_cached_gif.rs @@ -1,7 +1,6 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedGif { pub id: String, pub gif_file_id: String, diff --git a/src/core/types/inline_query_result_cached_mpeg4_gif.rs b/src/core/types/inline_query_result_cached_mpeg4_gif.rs index c52dbb5c..1754bdd8 100644 --- a/src/core/types/inline_query_result_cached_mpeg4_gif.rs +++ b/src/core/types/inline_query_result_cached_mpeg4_gif.rs @@ -1,10 +1,7 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedMpeg4Gif { - #[serde(rename = "type")] - pub query_type: String, pub id: String, pub mpeg4_file_id: String, pub title: Option, diff --git a/src/core/types/inline_query_result_cached_photo.rs b/src/core/types/inline_query_result_cached_photo.rs index 645808c5..248590ab 100644 --- a/src/core/types/inline_query_result_cached_photo.rs +++ b/src/core/types/inline_query_result_cached_photo.rs @@ -1,8 +1,6 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; -use crate::core::types::parse_mode::ParseMode; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; -#[derive(Debug, Serialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedPhoto { pub id: String, pub photo_file_id: String, diff --git a/src/core/types/inline_query_result_cached_sticker.rs b/src/core/types/inline_query_result_cached_sticker.rs index b53a7c31..25c85260 100644 --- a/src/core/types/inline_query_result_cached_sticker.rs +++ b/src/core/types/inline_query_result_cached_sticker.rs @@ -1,10 +1,7 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedSticker { - #[serde(rename = "type")] - pub query_type: String, pub id: String, pub sticker_file_id: String, pub reply_markup: Option, diff --git a/src/core/types/inline_query_result_cached_video.rs b/src/core/types/inline_query_result_cached_video.rs index 79907591..7968d0db 100644 --- a/src/core/types/inline_query_result_cached_video.rs +++ b/src/core/types/inline_query_result_cached_video.rs @@ -1,10 +1,7 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedVideo { - #[serde(rename = "type")] - pub query_type: String, pub id: String, pub video_file_id: String, pub title: String, diff --git a/src/core/types/inline_query_result_cached_voice.rs b/src/core/types/inline_query_result_cached_voice.rs index b4068cff..9ba3df3a 100644 --- a/src/core/types/inline_query_result_cached_voice.rs +++ b/src/core/types/inline_query_result_cached_voice.rs @@ -1,10 +1,7 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedVoice { - #[serde(rename = "type")] - pub query_type: String, pub id: String, pub voice_file_id: String, pub title: String, diff --git a/src/core/types/inline_query_result_contact.rs b/src/core/types/inline_query_result_contact.rs index 141aca39..88a22bd0 100644 --- a/src/core/types/inline_query_result_contact.rs +++ b/src/core/types/inline_query_result_contact.rs @@ -1,8 +1,6 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; -use crate::core::types::parse_mode::ParseMode; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; -#[derive(Debug, Serialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultContact { pub id: String, pub phone_number: String, diff --git a/src/core/types/inline_query_result_document.rs b/src/core/types/inline_query_result_document.rs index 23cb0a61..72895276 100644 --- a/src/core/types/inline_query_result_document.rs +++ b/src/core/types/inline_query_result_document.rs @@ -1,7 +1,6 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Serialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultDocument { pub id: String, pub title: String, diff --git a/src/core/types/inline_query_result_game.rs b/src/core/types/inline_query_result_game.rs index 5ce90f86..d81643b4 100644 --- a/src/core/types/inline_query_result_game.rs +++ b/src/core/types/inline_query_result_game.rs @@ -1,8 +1,6 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; -use crate::core::types::parse_mode::ParseMode; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; -#[derive(Debug, Serialize, Clone, PartialEq)] +#[derive(Debug, Serialize, Hash, PartialEq, Eq, Clone)] pub struct InlineQueryResultGame { pub id: String, pub game_short_name: String, diff --git a/src/core/types/inline_query_result_gif.rs b/src/core/types/inline_query_result_gif.rs index cf5ec79a..54f9d8cb 100644 --- a/src/core/types/inline_query_result_gif.rs +++ b/src/core/types/inline_query_result_gif.rs @@ -1,10 +1,7 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultGif { - #[serde(rename = "type")] - pub query_type: String, pub id: String, pub gif_url: String, pub gif_width: Option, diff --git a/src/core/types/inline_query_result_location.rs b/src/core/types/inline_query_result_location.rs index 77feb856..dc06c07b 100644 --- a/src/core/types/inline_query_result_location.rs +++ b/src/core/types/inline_query_result_location.rs @@ -1,8 +1,6 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; -use crate::core::types::parse_mode::ParseMode; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; -#[derive(Debug, Serialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultLocation { pub id: String, pub latitude: f64, diff --git a/src/core/types/inline_query_result_mpeg4_gif.rs b/src/core/types/inline_query_result_mpeg4_gif.rs index ce72ee01..d9dfa407 100644 --- a/src/core/types/inline_query_result_mpeg4_gif.rs +++ b/src/core/types/inline_query_result_mpeg4_gif.rs @@ -1,10 +1,7 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultMpeg4Gif { - #[serde(rename = "type")] - pub query_type: String, pub id: String, pub mpeg4_url: String, pub mpeg4_width: Option, diff --git a/src/core/types/inline_query_result_photo.rs b/src/core/types/inline_query_result_photo.rs index dcc67185..f312af43 100644 --- a/src/core/types/inline_query_result_photo.rs +++ b/src/core/types/inline_query_result_photo.rs @@ -1,10 +1,7 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultPhoto { - #[serde(rename = "type")] - pub query_type: String, pub id: String, pub photo_url: String, pub thumb_url: String, diff --git a/src/core/types/inline_query_result_venue.rs b/src/core/types/inline_query_result_venue.rs index 1dfd9a37..724cd12f 100644 --- a/src/core/types/inline_query_result_venue.rs +++ b/src/core/types/inline_query_result_venue.rs @@ -1,8 +1,6 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; -use crate::core::types::parse_mode::ParseMode; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; -#[derive(Debug, Serialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultVenue { pub id: String, pub latitude: f64, diff --git a/src/core/types/inline_query_result_video.rs b/src/core/types/inline_query_result_video.rs index 56b9f9ce..d2b3927e 100644 --- a/src/core/types/inline_query_result_video.rs +++ b/src/core/types/inline_query_result_video.rs @@ -1,10 +1,7 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultVideo { - #[serde(rename = "type")] - pub query_type: String, pub id: String, pub video_url: String, pub mime_type: String, diff --git a/src/core/types/inline_query_result_voice.rs b/src/core/types/inline_query_result_voice.rs index 25624795..859f48a3 100644 --- a/src/core/types/inline_query_result_voice.rs +++ b/src/core/types/inline_query_result_voice.rs @@ -1,7 +1,6 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultVoice { pub id: String, pub voice_url: String, diff --git a/src/core/types/input_message_content.rs b/src/core/types/input_message_content.rs index 0a23878f..30077945 100644 --- a/src/core/types/input_message_content.rs +++ b/src/core/types/input_message_content.rs @@ -2,7 +2,7 @@ use serde::Serialize; use crate::core::types::ParseMode; -#[derive(Debug, Serialize, Clone)] +#[derive(Debug, Serialize, Clone, PartialEq)] #[serde(untagged)] /// This object represents the content of a message to be sent as /// a result of an inline query. diff --git a/src/core/types/mod.rs b/src/core/types/mod.rs index d8d73f97..1d81a65e 100644 --- a/src/core/types/mod.rs +++ b/src/core/types/mod.rs @@ -47,6 +47,8 @@ pub use self::{ video_note::VideoNote, voice::Voice, file::File, + input_message_content::InputMessageContent, + inline_query::InlineQuery, inline_query_result::InlineQueryResult, inline_query_result_cached_audio::InlineQueryResultCachedAudio, @@ -117,6 +119,7 @@ mod video; mod video_note; mod voice; mod file; +mod input_message_content; mod inline_query; mod inline_query_result;