From 52417addca9163b4dfa417d2ce8b012e3bc8d0f1 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Fri, 22 Nov 2024 10:32:57 +0200 Subject: [PATCH 01/10] fix: fix serialization of InlineQueryResult --- src/api_params.rs | 73 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 19 deletions(-) diff --git a/src/api_params.rs b/src/api_params.rs index 787bf78..5bb122c 100644 --- a/src/api_params.rs +++ b/src/api_params.rs @@ -55,44 +55,79 @@ impl From for FileUpload { #[serde(tag = "type")] pub enum InlineQueryResult { #[serde(rename = "audio")] - CachedAudio(InlineQueryResultCachedAudio), + AudioOrCachedAudio(InlineQueryResultAudioOrCachedAudio), #[serde(rename = "document")] - CachedDocument(InlineQueryResultCachedDocument), + DocumentOrCachedDocument(InlineQueryResultDocumentOrCachedDocument), #[serde(rename = "gif")] - CachedGif(InlineQueryResultCachedGif), + GifOrCachedGif(InlineQueryResultGifOrCachedGif), #[serde(rename = "mpeg4_gif")] - CachedMpeg4Gif(InlineQueryResultCachedMpeg4Gif), + Mpeg4GifOrCachedMpeg4Gif(InlineQueryResultMpeg4GifOrCachedMpeg4Gif), #[serde(rename = "photo")] - CachedPhoto(InlineQueryResultCachedPhoto), + PhotoOrCachedPhoto(InlineQueryResultPhotoOrCachedPhoto), #[serde(rename = "sticker")] CachedSticker(InlineQueryResultCachedSticker), #[serde(rename = "video")] - CachedVideo(InlineQueryResultCachedVideo), + VideoOrCachedVideo(InlineQueryResultVideoOrCachedVideo), #[serde(rename = "voice")] - CachedVoice(InlineQueryResultCachedVoice), + VoiceOrCachedVoice(InlineQueryResultVoiceOrCachedVoice), #[serde(rename = "article")] Article(InlineQueryResultArticle), - #[serde(rename = "audio")] - Audio(InlineQueryResultAudio), #[serde(rename = "contract")] Contact(InlineQueryResultContact), #[serde(rename = "game")] Game(InlineQueryResultGame), - #[serde(rename = "document")] - Document(InlineQueryResultDocument), - #[serde(rename = "gif")] - Gif(InlineQueryResultGif), #[serde(rename = "location")] Location(InlineQueryResultLocation), - #[serde(rename = "mpeg4_gif")] - Mpeg4Gif(InlineQueryResultMpeg4Gif), - #[serde(rename = "photo")] - Photo(InlineQueryResultPhoto), #[serde(rename = "venue")] Venue(InlineQueryResultVenue), - #[serde(rename = "video")] +} + +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[serde(untagged)] +pub enum InlineQueryResultAudioOrCachedAudio { + CachedAudio(InlineQueryResultCachedAudio), + Audio(InlineQueryResultAudio), +} + +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[serde(untagged)] +pub enum InlineQueryResultDocumentOrCachedDocument { + CachedDocument(InlineQueryResultCachedDocument), + Document(InlineQueryResultDocument), +} + +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[serde(untagged)] +pub enum InlineQueryResultGifOrCachedGif { + CachedGif(InlineQueryResultCachedGif), + Gif(InlineQueryResultGif), +} + +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[serde(untagged)] +pub enum InlineQueryResultMpeg4GifOrCachedMpeg4Gif { + CachedMpeg4Gif(InlineQueryResultCachedMpeg4Gif), + Mpeg4Gif(InlineQueryResultMpeg4Gif), +} + +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[serde(untagged)] +pub enum InlineQueryResultPhotoOrCachedPhoto { + CachedPhoto(InlineQueryResultCachedPhoto), + Photo(InlineQueryResultPhoto), +} + +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[serde(untagged)] +pub enum InlineQueryResultVideoOrCachedVideo { + CachedVideo(InlineQueryResultCachedVideo), Video(InlineQueryResultVideo), - #[serde(rename = "voice")] +} + +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[serde(untagged)] +pub enum InlineQueryResultVoiceOrCachedVoice { + CachedVoice(InlineQueryResultCachedVoice), Voice(InlineQueryResultVoice), } From c43fab7b2d5fba36d72a51809c9b874d87a24c7b Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Fri, 22 Nov 2024 10:38:14 +0200 Subject: [PATCH 02/10] fix rust analyzer --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index c96fc03..5d2044a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ async-telegram-trait = ["dep:async-trait"] [lints.rust] unsafe_code = "forbid" +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(rust_analyzer)'] } [lints.clippy] pedantic = { level = "warn", priority = -1 } nursery = { level = "warn", priority = -1 } From c44be58f3629e90248de20ef9a53f284534feee4 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Fri, 22 Nov 2024 14:14:39 +0200 Subject: [PATCH 03/10] code review comment --- src/api_params.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/api_params.rs b/src/api_params.rs index 5bb122c..83e9286 100644 --- a/src/api_params.rs +++ b/src/api_params.rs @@ -55,21 +55,21 @@ impl From for FileUpload { #[serde(tag = "type")] pub enum InlineQueryResult { #[serde(rename = "audio")] - AudioOrCachedAudio(InlineQueryResultAudioOrCachedAudio), + Audio(InlineQueryResultAudioOrCachedAudio), #[serde(rename = "document")] - DocumentOrCachedDocument(InlineQueryResultDocumentOrCachedDocument), + Document(InlineQueryResultDocumentOrCachedDocument), #[serde(rename = "gif")] - GifOrCachedGif(InlineQueryResultGifOrCachedGif), + Gif(InlineQueryResultGifOrCachedGif), #[serde(rename = "mpeg4_gif")] - Mpeg4GifOrCachedMpeg4Gif(InlineQueryResultMpeg4GifOrCachedMpeg4Gif), + Mpeg4Gif(InlineQueryResultMpeg4GifOrCachedMpeg4Gif), #[serde(rename = "photo")] - PhotoOrCachedPhoto(InlineQueryResultPhotoOrCachedPhoto), + Photo(InlineQueryResultPhotoOrCachedPhoto), #[serde(rename = "sticker")] CachedSticker(InlineQueryResultCachedSticker), #[serde(rename = "video")] - VideoOrCachedVideo(InlineQueryResultVideoOrCachedVideo), + Video(InlineQueryResultVideoOrCachedVideo), #[serde(rename = "voice")] - VoiceOrCachedVoice(InlineQueryResultVoiceOrCachedVoice), + Voice(InlineQueryResultVoiceOrCachedVoice), #[serde(rename = "article")] Article(InlineQueryResultArticle), #[serde(rename = "contract")] From f74e99fbcbc21c1d313f5bfc7006bd4a83f0d6b5 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Fri, 22 Nov 2024 14:17:49 +0200 Subject: [PATCH 04/10] forgotten rename --- src/api_params.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/api_params.rs b/src/api_params.rs index 83e9286..e596cae 100644 --- a/src/api_params.rs +++ b/src/api_params.rs @@ -55,21 +55,21 @@ impl From for FileUpload { #[serde(tag = "type")] pub enum InlineQueryResult { #[serde(rename = "audio")] - Audio(InlineQueryResultAudioOrCachedAudio), + Audio(AudioOrCachedAudio), #[serde(rename = "document")] - Document(InlineQueryResultDocumentOrCachedDocument), + Document(DocumentOrCachedDocument), #[serde(rename = "gif")] - Gif(InlineQueryResultGifOrCachedGif), + Gif(GifOrCachedGif), #[serde(rename = "mpeg4_gif")] - Mpeg4Gif(InlineQueryResultMpeg4GifOrCachedMpeg4Gif), + Mpeg4Gif(Mpeg4GifOrCachedMpeg4Gif), #[serde(rename = "photo")] - Photo(InlineQueryResultPhotoOrCachedPhoto), + Photo(PhotoOrCachedPhoto), #[serde(rename = "sticker")] CachedSticker(InlineQueryResultCachedSticker), #[serde(rename = "video")] - Video(InlineQueryResultVideoOrCachedVideo), + Video(VideoOrCachedVideo), #[serde(rename = "voice")] - Voice(InlineQueryResultVoiceOrCachedVoice), + Voice(VoiceOrCachedVoice), #[serde(rename = "article")] Article(InlineQueryResultArticle), #[serde(rename = "contract")] @@ -84,49 +84,49 @@ pub enum InlineQueryResult { #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] #[serde(untagged)] -pub enum InlineQueryResultAudioOrCachedAudio { +pub enum AudioOrCachedAudio { CachedAudio(InlineQueryResultCachedAudio), Audio(InlineQueryResultAudio), } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] #[serde(untagged)] -pub enum InlineQueryResultDocumentOrCachedDocument { +pub enum DocumentOrCachedDocument { CachedDocument(InlineQueryResultCachedDocument), Document(InlineQueryResultDocument), } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] #[serde(untagged)] -pub enum InlineQueryResultGifOrCachedGif { +pub enum GifOrCachedGif { CachedGif(InlineQueryResultCachedGif), Gif(InlineQueryResultGif), } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] #[serde(untagged)] -pub enum InlineQueryResultMpeg4GifOrCachedMpeg4Gif { +pub enum Mpeg4GifOrCachedMpeg4Gif { CachedMpeg4Gif(InlineQueryResultCachedMpeg4Gif), Mpeg4Gif(InlineQueryResultMpeg4Gif), } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] #[serde(untagged)] -pub enum InlineQueryResultPhotoOrCachedPhoto { +pub enum PhotoOrCachedPhoto { CachedPhoto(InlineQueryResultCachedPhoto), Photo(InlineQueryResultPhoto), } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] #[serde(untagged)] -pub enum InlineQueryResultVideoOrCachedVideo { +pub enum VideoOrCachedVideo { CachedVideo(InlineQueryResultCachedVideo), Video(InlineQueryResultVideo), } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] #[serde(untagged)] -pub enum InlineQueryResultVoiceOrCachedVoice { +pub enum VoiceOrCachedVoice { CachedVoice(InlineQueryResultCachedVoice), Voice(InlineQueryResultVoice), } From e82ab3fb9d76d68587a030befb43a0ba51e21056 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Fri, 22 Nov 2024 15:57:42 +0200 Subject: [PATCH 05/10] `Either` enum --- src/api_params.rs | 62 ++++++++--------------------------------------- 1 file changed, 10 insertions(+), 52 deletions(-) diff --git a/src/api_params.rs b/src/api_params.rs index e596cae..2e22f47 100644 --- a/src/api_params.rs +++ b/src/api_params.rs @@ -55,21 +55,21 @@ impl From for FileUpload { #[serde(tag = "type")] pub enum InlineQueryResult { #[serde(rename = "audio")] - Audio(AudioOrCachedAudio), + Audio(Either), #[serde(rename = "document")] - Document(DocumentOrCachedDocument), + Document(Either), #[serde(rename = "gif")] - Gif(GifOrCachedGif), + Gif(Either), #[serde(rename = "mpeg4_gif")] - Mpeg4Gif(Mpeg4GifOrCachedMpeg4Gif), + Mpeg4Gif(Either), #[serde(rename = "photo")] - Photo(PhotoOrCachedPhoto), + Photo(Either), #[serde(rename = "sticker")] CachedSticker(InlineQueryResultCachedSticker), #[serde(rename = "video")] - Video(VideoOrCachedVideo), + Video(Either), #[serde(rename = "voice")] - Voice(VoiceOrCachedVoice), + Voice(Either), #[serde(rename = "article")] Article(InlineQueryResultArticle), #[serde(rename = "contract")] @@ -84,51 +84,9 @@ pub enum InlineQueryResult { #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] #[serde(untagged)] -pub enum AudioOrCachedAudio { - CachedAudio(InlineQueryResultCachedAudio), - Audio(InlineQueryResultAudio), -} - -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -#[serde(untagged)] -pub enum DocumentOrCachedDocument { - CachedDocument(InlineQueryResultCachedDocument), - Document(InlineQueryResultDocument), -} - -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -#[serde(untagged)] -pub enum GifOrCachedGif { - CachedGif(InlineQueryResultCachedGif), - Gif(InlineQueryResultGif), -} - -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -#[serde(untagged)] -pub enum Mpeg4GifOrCachedMpeg4Gif { - CachedMpeg4Gif(InlineQueryResultCachedMpeg4Gif), - Mpeg4Gif(InlineQueryResultMpeg4Gif), -} - -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -#[serde(untagged)] -pub enum PhotoOrCachedPhoto { - CachedPhoto(InlineQueryResultCachedPhoto), - Photo(InlineQueryResultPhoto), -} - -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -#[serde(untagged)] -pub enum VideoOrCachedVideo { - CachedVideo(InlineQueryResultCachedVideo), - Video(InlineQueryResultVideo), -} - -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -#[serde(untagged)] -pub enum VoiceOrCachedVoice { - CachedVoice(InlineQueryResultCachedVoice), - Voice(InlineQueryResultVoice), +pub enum Either { + Variant1(T1), + Variant2(T2), } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] From 020354d5fc76127faec3c3306458a1d433e8de09 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Fri, 22 Nov 2024 16:02:10 +0200 Subject: [PATCH 06/10] fix clippy --- src/api_params.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api_params.rs b/src/api_params.rs index 2e22f47..8f67c03 100644 --- a/src/api_params.rs +++ b/src/api_params.rs @@ -82,7 +82,7 @@ pub enum InlineQueryResult { Venue(InlineQueryResultVenue), } -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] #[serde(untagged)] pub enum Either { Variant1(T1), From c490230f96f6b0ca2b50c5a3ad3ed490e47142bd Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 26 Nov 2024 20:56:58 +0200 Subject: [PATCH 07/10] code review comment --- src/api_params.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/api_params.rs b/src/api_params.rs index 8f67c03..ee203c0 100644 --- a/src/api_params.rs +++ b/src/api_params.rs @@ -55,21 +55,21 @@ impl From for FileUpload { #[serde(tag = "type")] pub enum InlineQueryResult { #[serde(rename = "audio")] - Audio(Either), + Audio(MaybeCached), #[serde(rename = "document")] - Document(Either), + Document(MaybeCached), #[serde(rename = "gif")] - Gif(Either), + Gif(MaybeCached), #[serde(rename = "mpeg4_gif")] - Mpeg4Gif(Either), + Mpeg4Gif(MaybeCached), #[serde(rename = "photo")] - Photo(Either), + Photo(MaybeCached), #[serde(rename = "sticker")] CachedSticker(InlineQueryResultCachedSticker), #[serde(rename = "video")] - Video(Either), + Video(MaybeCached), #[serde(rename = "voice")] - Voice(Either), + Voice(MaybeCached), #[serde(rename = "article")] Article(InlineQueryResultArticle), #[serde(rename = "contract")] @@ -84,9 +84,9 @@ pub enum InlineQueryResult { #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] #[serde(untagged)] -pub enum Either { - Variant1(T1), - Variant2(T2), +pub enum MaybeCached { + Cached(T1), + NotCached(T2), } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] From 75c5ed275c6ccefeae8eddb3d3ecc4e16f6753b7 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 26 Nov 2024 20:58:51 +0200 Subject: [PATCH 08/10] Update src/api_params.rs Co-authored-by: EdJoPaTo --- src/api_params.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api_params.rs b/src/api_params.rs index ee203c0..5252be4 100644 --- a/src/api_params.rs +++ b/src/api_params.rs @@ -52,7 +52,7 @@ impl From for FileUpload { } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -#[serde(tag = "type")] +#[serde(tag = "type", rename_all = "snake_case")] pub enum InlineQueryResult { #[serde(rename = "audio")] Audio(MaybeCached), From 6eb243b117e84b9fbb0cd5e13354176d592e1371 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 26 Nov 2024 20:58:59 +0200 Subject: [PATCH 09/10] Update src/api_params.rs Co-authored-by: EdJoPaTo --- src/api_params.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api_params.rs b/src/api_params.rs index 5252be4..2f292c8 100644 --- a/src/api_params.rs +++ b/src/api_params.rs @@ -65,7 +65,7 @@ pub enum InlineQueryResult { #[serde(rename = "photo")] Photo(MaybeCached), #[serde(rename = "sticker")] - CachedSticker(InlineQueryResultCachedSticker), + Sticker(InlineQueryResultCachedSticker), #[serde(rename = "video")] Video(MaybeCached), #[serde(rename = "voice")] From 48edd68d84f6e783f420d5ab33673147bae5c2c2 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 26 Nov 2024 21:02:08 +0200 Subject: [PATCH 10/10] remove renames --- src/api_params.rs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/api_params.rs b/src/api_params.rs index 2f292c8..44a8524 100644 --- a/src/api_params.rs +++ b/src/api_params.rs @@ -54,31 +54,18 @@ impl From for FileUpload { #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] #[serde(tag = "type", rename_all = "snake_case")] pub enum InlineQueryResult { - #[serde(rename = "audio")] Audio(MaybeCached), - #[serde(rename = "document")] Document(MaybeCached), - #[serde(rename = "gif")] Gif(MaybeCached), - #[serde(rename = "mpeg4_gif")] Mpeg4Gif(MaybeCached), - #[serde(rename = "photo")] Photo(MaybeCached), - #[serde(rename = "sticker")] Sticker(InlineQueryResultCachedSticker), - #[serde(rename = "video")] Video(MaybeCached), - #[serde(rename = "voice")] Voice(MaybeCached), - #[serde(rename = "article")] Article(InlineQueryResultArticle), - #[serde(rename = "contract")] Contact(InlineQueryResultContact), - #[serde(rename = "game")] Game(InlineQueryResultGame), - #[serde(rename = "location")] Location(InlineQueryResultLocation), - #[serde(rename = "venue")] Venue(InlineQueryResultVenue), }