From 1a6b10ffad023ae8288092357651821ff6cd54eb Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 26 Nov 2024 21:27:56 +0200 Subject: [PATCH] fix: fix serialization of InlineQueryResult (#230) * fix: fix serialization of InlineQueryResult * fix rust analyzer * code review comment * forgotten rename * `Either` enum * fix clippy * code review comment * Update src/api_params.rs Co-authored-by: EdJoPaTo * Update src/api_params.rs Co-authored-by: EdJoPaTo * remove renames --------- Co-authored-by: EdJoPaTo --- Cargo.toml | 1 + src/api_params.rs | 52 +++++++++++++++-------------------------------- 2 files changed, 17 insertions(+), 36 deletions(-) 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 } diff --git a/src/api_params.rs b/src/api_params.rs index 787bf78..44a8524 100644 --- a/src/api_params.rs +++ b/src/api_params.rs @@ -52,48 +52,28 @@ 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")] - 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), - #[serde(rename = "article")] + Audio(MaybeCached), + Document(MaybeCached), + Gif(MaybeCached), + Mpeg4Gif(MaybeCached), + Photo(MaybeCached), + Sticker(InlineQueryResultCachedSticker), + Video(MaybeCached), + Voice(MaybeCached), 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")] - Video(InlineQueryResultVideo), - #[serde(rename = "voice")] - Voice(InlineQueryResultVoice), +} + +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] +#[serde(untagged)] +pub enum MaybeCached { + Cached(T1), + NotCached(T2), } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]