From 4870338a751de197a8e997287d8a32030eee9734 Mon Sep 17 00:00:00 2001 From: Andrey Brusnik Date: Tue, 30 Jul 2024 17:27:16 +0400 Subject: [PATCH] Replace `Option` with `bool` in LinkPreviewOptions --- .../src/types/inline_query_result.rs | 128 +++++++++--------- .../src/types/input_message_content.rs | 8 +- .../src/types/link_preview_options.rs | 12 +- crates/teloxide-core/src/types/update.rs | 8 +- 4 files changed, 80 insertions(+), 76 deletions(-) diff --git a/crates/teloxide-core/src/types/inline_query_result.rs b/crates/teloxide-core/src/types/inline_query_result.rs index 1d58fd56..45f658ff 100644 --- a/crates/teloxide-core/src/types/inline_query_result.rs +++ b/crates/teloxide-core/src/types/inline_query_result.rs @@ -305,11 +305,11 @@ mod tests { parse_mode: Some(ParseMode::MarkdownV2), entities: None, link_preview_options: Some(LinkPreviewOptions { - is_disabled: Some(true), + is_disabled: true, url: None, - prefer_small_media: None, - prefer_large_media: None, - show_above_text: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, }), })), caption_entities: None, @@ -359,11 +359,11 @@ mod tests { parse_mode: Some(ParseMode::MarkdownV2), entities: None, link_preview_options: Some(LinkPreviewOptions { - is_disabled: Some(true), + is_disabled: true, url: None, - prefer_small_media: None, - prefer_large_media: None, - show_above_text: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, }), })), caption_entities: None, @@ -414,11 +414,11 @@ mod tests { parse_mode: Some(ParseMode::MarkdownV2), entities: None, link_preview_options: Some(LinkPreviewOptions { - is_disabled: Some(true), + is_disabled: true, url: None, - prefer_small_media: None, - prefer_large_media: None, - show_above_text: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, }), })), caption_entities: None, @@ -473,11 +473,11 @@ mod tests { parse_mode: Some(ParseMode::MarkdownV2), entities: None, link_preview_options: Some(LinkPreviewOptions { - is_disabled: Some(true), + is_disabled: true, url: None, - prefer_small_media: None, - prefer_large_media: None, - show_above_text: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, }), })), thumbnail_url: Some(reqwest::Url::parse("http://thumb_url/").unwrap()), @@ -527,11 +527,11 @@ mod tests { parse_mode: Some(ParseMode::MarkdownV2), entities: None, link_preview_options: Some(LinkPreviewOptions { - is_disabled: Some(true), + is_disabled: true, url: None, - prefer_small_media: None, - prefer_large_media: None, - show_above_text: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, }), })), }); @@ -588,11 +588,11 @@ mod tests { parse_mode: Some(ParseMode::MarkdownV2), entities: None, link_preview_options: Some(LinkPreviewOptions { - is_disabled: Some(true), + is_disabled: true, url: None, - prefer_small_media: None, - prefer_large_media: None, - show_above_text: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, }), })), }); @@ -639,11 +639,11 @@ mod tests { parse_mode: Some(ParseMode::MarkdownV2), entities: None, link_preview_options: Some(LinkPreviewOptions { - is_disabled: Some(true), + is_disabled: true, url: None, - prefer_small_media: None, - prefer_large_media: None, - show_above_text: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, }), })), }); @@ -700,11 +700,11 @@ mod tests { parse_mode: Some(ParseMode::MarkdownV2), entities: None, link_preview_options: Some(LinkPreviewOptions { - is_disabled: Some(true), + is_disabled: true, url: None, - prefer_small_media: None, - prefer_large_media: None, - show_above_text: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, }), })), }); @@ -753,11 +753,11 @@ mod tests { parse_mode: Some(ParseMode::MarkdownV2), entities: None, link_preview_options: Some(LinkPreviewOptions { - is_disabled: Some(true), + is_disabled: true, url: None, - prefer_small_media: None, - prefer_large_media: None, - show_above_text: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, }), })), }); @@ -812,11 +812,11 @@ mod tests { parse_mode: Some(ParseMode::MarkdownV2), entities: None, link_preview_options: Some(LinkPreviewOptions { - is_disabled: Some(true), + is_disabled: true, url: None, - prefer_small_media: None, - prefer_large_media: None, - show_above_text: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, }), })), }); @@ -855,11 +855,11 @@ mod tests { entities: None, parse_mode: Some(ParseMode::MarkdownV2), link_preview_options: Some(LinkPreviewOptions { - is_disabled: Some(true), + is_disabled: true, url: None, - prefer_small_media: None, - prefer_large_media: None, - show_above_text: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, }), })), }); @@ -1095,11 +1095,11 @@ mod tests { message_text: String::from("message_text"), entities: None, link_preview_options: Some(LinkPreviewOptions { - is_disabled: Some(true), + is_disabled: true, url: None, - prefer_small_media: None, - prefer_large_media: None, - show_above_text: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, }), parse_mode: None, }), @@ -1129,11 +1129,11 @@ mod tests { entities: None, parse_mode: None, link_preview_options: Some(LinkPreviewOptions { - is_disabled: Some(true), + is_disabled: true, url: None, - prefer_small_media: None, - prefer_large_media: None, - show_above_text: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, }), }), reply_markup: Some(InlineKeyboardMarkup::default()), @@ -1188,11 +1188,11 @@ mod tests { entities: None, parse_mode: None, link_preview_options: Some(LinkPreviewOptions { - is_disabled: Some(true), + is_disabled: true, url: None, - prefer_small_media: None, - prefer_large_media: None, - show_above_text: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, }), })), thumbnail_url: Some(Url::parse("http://thumb_url/").unwrap()), @@ -1280,11 +1280,11 @@ mod tests { entities: None, parse_mode: None, link_preview_options: Some(LinkPreviewOptions { - is_disabled: Some(true), + is_disabled: true, url: None, - prefer_small_media: None, - prefer_large_media: None, - show_above_text: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, }), })), thumbnail_url: Some(Url::parse("http://thumb_url/").unwrap()), @@ -1343,11 +1343,11 @@ mod tests { entities: None, parse_mode: None, link_preview_options: Some(LinkPreviewOptions { - is_disabled: Some(true), + is_disabled: true, url: None, - prefer_small_media: None, - prefer_large_media: None, - show_above_text: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, }), })), thumbnail_url: Some(Url::parse("http://thumb_url/").unwrap()), diff --git a/crates/teloxide-core/src/types/input_message_content.rs b/crates/teloxide-core/src/types/input_message_content.rs index ed517b7a..62c7da33 100644 --- a/crates/teloxide-core/src/types/input_message_content.rs +++ b/crates/teloxide-core/src/types/input_message_content.rs @@ -590,11 +590,11 @@ mod tests { parse_mode: None, entities: None, link_preview_options: Some(LinkPreviewOptions { - is_disabled: Some(true), + is_disabled: true, url: None, - prefer_small_media: None, - prefer_large_media: None, - show_above_text: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, }), }); diff --git a/crates/teloxide-core/src/types/link_preview_options.rs b/crates/teloxide-core/src/types/link_preview_options.rs index 4f56d8b0..96407e90 100644 --- a/crates/teloxide-core/src/types/link_preview_options.rs +++ b/crates/teloxide-core/src/types/link_preview_options.rs @@ -5,7 +5,8 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)] pub struct LinkPreviewOptions { /// `true`, if the link preview is disabled - pub is_disabled: Option, + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub is_disabled: bool, /// URL to use for the link preview. If empty, then the first URL found in /// the message text will be used @@ -14,16 +15,19 @@ pub struct LinkPreviewOptions { /// `true`, if the media in the link preview is suppposed to be shrunk; /// ignored if the URL isn't explicitly specified or media size change isn't /// supported for the preview - pub prefer_small_media: Option, + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub prefer_small_media: bool, /// `true`, if the media in the link preview is suppposed to be enlarged; /// ignored if the URL isn't explicitly specified or media size change isn't /// supported for the preview - pub prefer_large_media: Option, + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub prefer_large_media: bool, /// `true`, if the link preview must be shown above the message text; /// otherwise, the link preview will be shown below the message text - pub show_above_text: Option, + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub show_above_text: bool, } #[cfg(test)] diff --git a/crates/teloxide-core/src/types/update.rs b/crates/teloxide-core/src/types/update.rs index cdd0dd57..33d3f4a0 100644 --- a/crates/teloxide-core/src/types/update.rs +++ b/crates/teloxide-core/src/types/update.rs @@ -553,11 +553,11 @@ mod test { text: String::from("hello there"), entities: vec![], link_preview_options: Some(LinkPreviewOptions { - is_disabled: Some(true), + is_disabled: true, url: None, - prefer_small_media: None, - prefer_large_media: None, - show_above_text: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, }), }), reply_markup: None,