Replace Option<bool> with bool in LinkPreviewOptions

This commit is contained in:
Andrey Brusnik 2024-07-30 17:27:16 +04:00
parent ae88d60b4e
commit 4870338a75
No known key found for this signature in database
GPG key ID: D33232F28CFF442C
4 changed files with 80 additions and 76 deletions

View file

@ -305,11 +305,11 @@ mod tests {
parse_mode: Some(ParseMode::MarkdownV2), parse_mode: Some(ParseMode::MarkdownV2),
entities: None, entities: None,
link_preview_options: Some(LinkPreviewOptions { link_preview_options: Some(LinkPreviewOptions {
is_disabled: Some(true), is_disabled: true,
url: None, url: None,
prefer_small_media: None, prefer_small_media: false,
prefer_large_media: None, prefer_large_media: false,
show_above_text: None, show_above_text: false,
}), }),
})), })),
caption_entities: None, caption_entities: None,
@ -359,11 +359,11 @@ mod tests {
parse_mode: Some(ParseMode::MarkdownV2), parse_mode: Some(ParseMode::MarkdownV2),
entities: None, entities: None,
link_preview_options: Some(LinkPreviewOptions { link_preview_options: Some(LinkPreviewOptions {
is_disabled: Some(true), is_disabled: true,
url: None, url: None,
prefer_small_media: None, prefer_small_media: false,
prefer_large_media: None, prefer_large_media: false,
show_above_text: None, show_above_text: false,
}), }),
})), })),
caption_entities: None, caption_entities: None,
@ -414,11 +414,11 @@ mod tests {
parse_mode: Some(ParseMode::MarkdownV2), parse_mode: Some(ParseMode::MarkdownV2),
entities: None, entities: None,
link_preview_options: Some(LinkPreviewOptions { link_preview_options: Some(LinkPreviewOptions {
is_disabled: Some(true), is_disabled: true,
url: None, url: None,
prefer_small_media: None, prefer_small_media: false,
prefer_large_media: None, prefer_large_media: false,
show_above_text: None, show_above_text: false,
}), }),
})), })),
caption_entities: None, caption_entities: None,
@ -473,11 +473,11 @@ mod tests {
parse_mode: Some(ParseMode::MarkdownV2), parse_mode: Some(ParseMode::MarkdownV2),
entities: None, entities: None,
link_preview_options: Some(LinkPreviewOptions { link_preview_options: Some(LinkPreviewOptions {
is_disabled: Some(true), is_disabled: true,
url: None, url: None,
prefer_small_media: None, prefer_small_media: false,
prefer_large_media: None, prefer_large_media: false,
show_above_text: None, show_above_text: false,
}), }),
})), })),
thumbnail_url: Some(reqwest::Url::parse("http://thumb_url/").unwrap()), thumbnail_url: Some(reqwest::Url::parse("http://thumb_url/").unwrap()),
@ -527,11 +527,11 @@ mod tests {
parse_mode: Some(ParseMode::MarkdownV2), parse_mode: Some(ParseMode::MarkdownV2),
entities: None, entities: None,
link_preview_options: Some(LinkPreviewOptions { link_preview_options: Some(LinkPreviewOptions {
is_disabled: Some(true), is_disabled: true,
url: None, url: None,
prefer_small_media: None, prefer_small_media: false,
prefer_large_media: None, prefer_large_media: false,
show_above_text: None, show_above_text: false,
}), }),
})), })),
}); });
@ -588,11 +588,11 @@ mod tests {
parse_mode: Some(ParseMode::MarkdownV2), parse_mode: Some(ParseMode::MarkdownV2),
entities: None, entities: None,
link_preview_options: Some(LinkPreviewOptions { link_preview_options: Some(LinkPreviewOptions {
is_disabled: Some(true), is_disabled: true,
url: None, url: None,
prefer_small_media: None, prefer_small_media: false,
prefer_large_media: None, prefer_large_media: false,
show_above_text: None, show_above_text: false,
}), }),
})), })),
}); });
@ -639,11 +639,11 @@ mod tests {
parse_mode: Some(ParseMode::MarkdownV2), parse_mode: Some(ParseMode::MarkdownV2),
entities: None, entities: None,
link_preview_options: Some(LinkPreviewOptions { link_preview_options: Some(LinkPreviewOptions {
is_disabled: Some(true), is_disabled: true,
url: None, url: None,
prefer_small_media: None, prefer_small_media: false,
prefer_large_media: None, prefer_large_media: false,
show_above_text: None, show_above_text: false,
}), }),
})), })),
}); });
@ -700,11 +700,11 @@ mod tests {
parse_mode: Some(ParseMode::MarkdownV2), parse_mode: Some(ParseMode::MarkdownV2),
entities: None, entities: None,
link_preview_options: Some(LinkPreviewOptions { link_preview_options: Some(LinkPreviewOptions {
is_disabled: Some(true), is_disabled: true,
url: None, url: None,
prefer_small_media: None, prefer_small_media: false,
prefer_large_media: None, prefer_large_media: false,
show_above_text: None, show_above_text: false,
}), }),
})), })),
}); });
@ -753,11 +753,11 @@ mod tests {
parse_mode: Some(ParseMode::MarkdownV2), parse_mode: Some(ParseMode::MarkdownV2),
entities: None, entities: None,
link_preview_options: Some(LinkPreviewOptions { link_preview_options: Some(LinkPreviewOptions {
is_disabled: Some(true), is_disabled: true,
url: None, url: None,
prefer_small_media: None, prefer_small_media: false,
prefer_large_media: None, prefer_large_media: false,
show_above_text: None, show_above_text: false,
}), }),
})), })),
}); });
@ -812,11 +812,11 @@ mod tests {
parse_mode: Some(ParseMode::MarkdownV2), parse_mode: Some(ParseMode::MarkdownV2),
entities: None, entities: None,
link_preview_options: Some(LinkPreviewOptions { link_preview_options: Some(LinkPreviewOptions {
is_disabled: Some(true), is_disabled: true,
url: None, url: None,
prefer_small_media: None, prefer_small_media: false,
prefer_large_media: None, prefer_large_media: false,
show_above_text: None, show_above_text: false,
}), }),
})), })),
}); });
@ -855,11 +855,11 @@ mod tests {
entities: None, entities: None,
parse_mode: Some(ParseMode::MarkdownV2), parse_mode: Some(ParseMode::MarkdownV2),
link_preview_options: Some(LinkPreviewOptions { link_preview_options: Some(LinkPreviewOptions {
is_disabled: Some(true), is_disabled: true,
url: None, url: None,
prefer_small_media: None, prefer_small_media: false,
prefer_large_media: None, prefer_large_media: false,
show_above_text: None, show_above_text: false,
}), }),
})), })),
}); });
@ -1095,11 +1095,11 @@ mod tests {
message_text: String::from("message_text"), message_text: String::from("message_text"),
entities: None, entities: None,
link_preview_options: Some(LinkPreviewOptions { link_preview_options: Some(LinkPreviewOptions {
is_disabled: Some(true), is_disabled: true,
url: None, url: None,
prefer_small_media: None, prefer_small_media: false,
prefer_large_media: None, prefer_large_media: false,
show_above_text: None, show_above_text: false,
}), }),
parse_mode: None, parse_mode: None,
}), }),
@ -1129,11 +1129,11 @@ mod tests {
entities: None, entities: None,
parse_mode: None, parse_mode: None,
link_preview_options: Some(LinkPreviewOptions { link_preview_options: Some(LinkPreviewOptions {
is_disabled: Some(true), is_disabled: true,
url: None, url: None,
prefer_small_media: None, prefer_small_media: false,
prefer_large_media: None, prefer_large_media: false,
show_above_text: None, show_above_text: false,
}), }),
}), }),
reply_markup: Some(InlineKeyboardMarkup::default()), reply_markup: Some(InlineKeyboardMarkup::default()),
@ -1188,11 +1188,11 @@ mod tests {
entities: None, entities: None,
parse_mode: None, parse_mode: None,
link_preview_options: Some(LinkPreviewOptions { link_preview_options: Some(LinkPreviewOptions {
is_disabled: Some(true), is_disabled: true,
url: None, url: None,
prefer_small_media: None, prefer_small_media: false,
prefer_large_media: None, prefer_large_media: false,
show_above_text: None, show_above_text: false,
}), }),
})), })),
thumbnail_url: Some(Url::parse("http://thumb_url/").unwrap()), thumbnail_url: Some(Url::parse("http://thumb_url/").unwrap()),
@ -1280,11 +1280,11 @@ mod tests {
entities: None, entities: None,
parse_mode: None, parse_mode: None,
link_preview_options: Some(LinkPreviewOptions { link_preview_options: Some(LinkPreviewOptions {
is_disabled: Some(true), is_disabled: true,
url: None, url: None,
prefer_small_media: None, prefer_small_media: false,
prefer_large_media: None, prefer_large_media: false,
show_above_text: None, show_above_text: false,
}), }),
})), })),
thumbnail_url: Some(Url::parse("http://thumb_url/").unwrap()), thumbnail_url: Some(Url::parse("http://thumb_url/").unwrap()),
@ -1343,11 +1343,11 @@ mod tests {
entities: None, entities: None,
parse_mode: None, parse_mode: None,
link_preview_options: Some(LinkPreviewOptions { link_preview_options: Some(LinkPreviewOptions {
is_disabled: Some(true), is_disabled: true,
url: None, url: None,
prefer_small_media: None, prefer_small_media: false,
prefer_large_media: None, prefer_large_media: false,
show_above_text: None, show_above_text: false,
}), }),
})), })),
thumbnail_url: Some(Url::parse("http://thumb_url/").unwrap()), thumbnail_url: Some(Url::parse("http://thumb_url/").unwrap()),

View file

@ -590,11 +590,11 @@ mod tests {
parse_mode: None, parse_mode: None,
entities: None, entities: None,
link_preview_options: Some(LinkPreviewOptions { link_preview_options: Some(LinkPreviewOptions {
is_disabled: Some(true), is_disabled: true,
url: None, url: None,
prefer_small_media: None, prefer_small_media: false,
prefer_large_media: None, prefer_large_media: false,
show_above_text: None, show_above_text: false,
}), }),
}); });

View file

@ -5,7 +5,8 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
pub struct LinkPreviewOptions { pub struct LinkPreviewOptions {
/// `true`, if the link preview is disabled /// `true`, if the link preview is disabled
pub is_disabled: Option<bool>, #[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 /// URL to use for the link preview. If empty, then the first URL found in
/// the message text will be used /// 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; /// `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 /// ignored if the URL isn't explicitly specified or media size change isn't
/// supported for the preview /// supported for the preview
pub prefer_small_media: Option<bool>, #[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; /// `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 /// ignored if the URL isn't explicitly specified or media size change isn't
/// supported for the preview /// supported for the preview
pub prefer_large_media: Option<bool>, #[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; /// `true`, if the link preview must be shown above the message text;
/// otherwise, the link preview will be shown below the message text /// otherwise, the link preview will be shown below the message text
pub show_above_text: Option<bool>, #[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub show_above_text: bool,
} }
#[cfg(test)] #[cfg(test)]

View file

@ -553,11 +553,11 @@ mod test {
text: String::from("hello there"), text: String::from("hello there"),
entities: vec![], entities: vec![],
link_preview_options: Some(LinkPreviewOptions { link_preview_options: Some(LinkPreviewOptions {
is_disabled: Some(true), is_disabled: true,
url: None, url: None,
prefer_small_media: None, prefer_small_media: false,
prefer_large_media: None, prefer_large_media: false,
show_above_text: None, show_above_text: false,
}), }),
}), }),
reply_markup: None, reply_markup: None,