Use more precise types in inline query results

This commit is contained in:
Maybe Waffle 2023-06-05 17:36:15 +04:00
parent efd801bf2d
commit 15c742d90b
10 changed files with 47 additions and 44 deletions

View file

@ -58,6 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Forward::message_id` and `Message::forward_from_message_id` now use `MessageId` instead of `i32` ([#887][pr887]) - `Forward::message_id` and `Message::forward_from_message_id` now use `MessageId` instead of `i32` ([#887][pr887])
- `Poll::total_voter_count` and `PollOption::voter_count` now use `u32` instead of `i32` ([#887][pr887]) - `Poll::total_voter_count` and `PollOption::voter_count` now use `u32` instead of `i32` ([#887][pr887])
- `PollAnswer::option_ids` now use `u8` instead of `i32` ([#887][pr887]) - `PollAnswer::option_ids` now use `u8` instead of `i32` ([#887][pr887])
- Use `u32` for sizes and `Seconds` for timespans in `InlineQueryResult*` ([#887][pr887])
[pr852]: https://github.com/teloxide/teloxide/pull/853 [pr852]: https://github.com/teloxide/teloxide/pull/853
[pr859]: https://github.com/teloxide/teloxide/pull/859 [pr859]: https://github.com/teloxide/teloxide/pull/859

View file

@ -34,10 +34,10 @@ pub struct InlineQueryResultArticle {
pub thumb_url: Option<reqwest::Url>, pub thumb_url: Option<reqwest::Url>,
/// Thumbnail width. /// Thumbnail width.
pub thumb_width: Option<i32>, pub thumb_width: Option<u32>,
/// Thumbnail height. /// Thumbnail height.
pub thumb_height: Option<i32>, pub thumb_height: Option<u32>,
} }
impl InlineQueryResultArticle { impl InlineQueryResultArticle {
@ -115,13 +115,13 @@ impl InlineQueryResultArticle {
} }
#[must_use] #[must_use]
pub fn thumb_width(mut self, val: i32) -> Self { pub fn thumb_width(mut self, val: u32) -> Self {
self.thumb_width = Some(val); self.thumb_width = Some(val);
self self
} }
#[must_use] #[must_use]
pub fn thumb_height(mut self, val: i32) -> Self { pub fn thumb_height(mut self, val: u32) -> Self {
self.thumb_height = Some(val); self.thumb_height = Some(val);
self self
} }

View file

@ -42,10 +42,10 @@ pub struct InlineQueryResultContact {
pub thumb_url: Option<reqwest::Url>, pub thumb_url: Option<reqwest::Url>,
/// Thumbnail width. /// Thumbnail width.
pub thumb_width: Option<i32>, pub thumb_width: Option<u32>,
/// Thumbnail height. /// Thumbnail height.
pub thumb_height: Option<i32>, pub thumb_height: Option<u32>,
} }
impl InlineQueryResultContact { impl InlineQueryResultContact {
@ -128,13 +128,13 @@ impl InlineQueryResultContact {
} }
#[must_use] #[must_use]
pub fn thumb_width(mut self, val: i32) -> Self { pub fn thumb_width(mut self, val: u32) -> Self {
self.thumb_width = Some(val); self.thumb_width = Some(val);
self self
} }
#[must_use] #[must_use]
pub fn thumb_height(mut self, val: i32) -> Self { pub fn thumb_height(mut self, val: u32) -> Self {
self.thumb_height = Some(val); self.thumb_height = Some(val);
self self
} }

View file

@ -56,10 +56,10 @@ pub struct InlineQueryResultDocument {
pub thumb_url: Option<reqwest::Url>, pub thumb_url: Option<reqwest::Url>,
/// Thumbnail width. /// Thumbnail width.
pub thumb_width: Option<i32>, pub thumb_width: Option<u32>,
/// Thumbnail height. /// Thumbnail height.
pub thumb_height: Option<i32>, pub thumb_height: Option<u32>,
} }
impl InlineQueryResultDocument { impl InlineQueryResultDocument {
@ -140,13 +140,13 @@ impl InlineQueryResultDocument {
} }
#[must_use] #[must_use]
pub fn thumb_width(mut self, val: i32) -> Self { pub fn thumb_width(mut self, val: u32) -> Self {
self.thumb_width = Some(val); self.thumb_width = Some(val);
self self
} }
#[must_use] #[must_use]
pub fn thumb_height(mut self, val: i32) -> Self { pub fn thumb_height(mut self, val: u32) -> Self {
self.thumb_height = Some(val); self.thumb_height = Some(val);
self self
} }

View file

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::types::{InlineKeyboardMarkup, InputMessageContent, MessageEntity, ParseMode}; use crate::types::{InlineKeyboardMarkup, InputMessageContent, MessageEntity, ParseMode, Seconds};
/// Represents a link to an animated GIF file. /// Represents a link to an animated GIF file.
/// ///
@ -19,13 +19,13 @@ pub struct InlineQueryResultGif {
pub gif_url: reqwest::Url, pub gif_url: reqwest::Url,
/// Width of the GIF. /// Width of the GIF.
pub gif_width: Option<i32>, pub gif_width: Option<u32>,
/// Height of the GIFv. /// Height of the GIFv.
pub gif_height: Option<i32>, pub gif_height: Option<u32>,
/// Duration of the GIF. /// Duration of the GIF.
pub gif_duration: Option<i32>, pub gif_duration: Option<Seconds>,
/// URL of the static thumbnail for the result (jpeg or gif). /// URL of the static thumbnail for the result (jpeg or gif).
pub thumb_url: reqwest::Url, pub thumb_url: reqwest::Url,
@ -93,19 +93,19 @@ impl InlineQueryResultGif {
} }
#[must_use] #[must_use]
pub fn gif_width(mut self, val: i32) -> Self { pub fn gif_width(mut self, val: u32) -> Self {
self.gif_width = Some(val); self.gif_width = Some(val);
self self
} }
#[must_use] #[must_use]
pub fn gif_height(mut self, val: i32) -> Self { pub fn gif_height(mut self, val: u32) -> Self {
self.gif_height = Some(val); self.gif_height = Some(val);
self self
} }
#[must_use] #[must_use]
pub fn gif_duration(mut self, val: i32) -> Self { pub fn gif_duration(mut self, val: Seconds) -> Self {
self.gif_duration = Some(val); self.gif_duration = Some(val);
self self
} }

View file

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::types::{InlineKeyboardMarkup, InputMessageContent, MessageEntity, ParseMode}; use crate::types::{InlineKeyboardMarkup, InputMessageContent, MessageEntity, ParseMode, Seconds};
/// Represents a link to a video animation (H.264/MPEG-4 AVC video without /// Represents a link to a video animation (H.264/MPEG-4 AVC video without
/// sound). /// sound).
@ -16,17 +16,19 @@ pub struct InlineQueryResultMpeg4Gif {
/// Unique identifier for this result, 1-64 bytes. /// Unique identifier for this result, 1-64 bytes.
pub id: String, pub id: String,
// FIXME: rename everything so that it doesn't have `mpeg4_` (and similarly for other
// `InlineQueryResult*`)
/// A valid URL for the MP4 file. File size must not exceed 1MB. /// A valid URL for the MP4 file. File size must not exceed 1MB.
pub mpeg4_url: reqwest::Url, pub mpeg4_url: reqwest::Url,
/// Video width. /// Video width.
pub mpeg4_width: Option<i32>, pub mpeg4_width: Option<u32>,
/// Video height. /// Video height.
pub mpeg4_height: Option<i32>, pub mpeg4_height: Option<u32>,
/// Video duration. /// Video duration.
pub mpeg4_duration: Option<i32>, pub mpeg4_duration: Option<Seconds>,
/// URL of the static thumbnail (jpeg or gif) for the result. /// URL of the static thumbnail (jpeg or gif) for the result.
pub thumb_url: reqwest::Url, pub thumb_url: reqwest::Url,
@ -94,19 +96,19 @@ impl InlineQueryResultMpeg4Gif {
} }
#[must_use] #[must_use]
pub fn mpeg4_width(mut self, val: i32) -> Self { pub fn mpeg4_width(mut self, val: u32) -> Self {
self.mpeg4_width = Some(val); self.mpeg4_width = Some(val);
self self
} }
#[must_use] #[must_use]
pub fn mpeg4_height(mut self, val: i32) -> Self { pub fn mpeg4_height(mut self, val: u32) -> Self {
self.mpeg4_height = Some(val); self.mpeg4_height = Some(val);
self self
} }
#[must_use] #[must_use]
pub fn mpeg4_duration(mut self, val: i32) -> Self { pub fn mpeg4_duration(mut self, val: Seconds) -> Self {
self.mpeg4_duration = Some(val); self.mpeg4_duration = Some(val);
self self
} }

View file

@ -23,10 +23,10 @@ pub struct InlineQueryResultPhoto {
pub thumb_url: reqwest::Url, pub thumb_url: reqwest::Url,
/// Width of the photo. /// Width of the photo.
pub photo_width: Option<i32>, pub photo_width: Option<u32>,
/// Height of the photo. /// Height of the photo.
pub photo_height: Option<i32>, pub photo_height: Option<u32>,
/// Title for the result. /// Title for the result.
pub title: Option<String>, pub title: Option<String>,
@ -100,13 +100,13 @@ impl InlineQueryResultPhoto {
} }
#[must_use] #[must_use]
pub fn photo_width(mut self, val: i32) -> Self { pub fn photo_width(mut self, val: u32) -> Self {
self.photo_width = Some(val); self.photo_width = Some(val);
self self
} }
#[must_use] #[must_use]
pub fn photo_height(mut self, val: i32) -> Self { pub fn photo_height(mut self, val: u32) -> Self {
self.photo_height = Some(val); self.photo_height = Some(val);
self self
} }

View file

@ -55,10 +55,10 @@ pub struct InlineQueryResultVenue {
pub thumb_url: Option<reqwest::Url>, pub thumb_url: Option<reqwest::Url>,
/// Thumbnail width. /// Thumbnail width.
pub thumb_width: Option<i32>, pub thumb_width: Option<u32>,
/// Thumbnail height. /// Thumbnail height.
pub thumb_height: Option<i32>, pub thumb_height: Option<u32>,
} }
impl InlineQueryResultVenue { impl InlineQueryResultVenue {
@ -173,13 +173,13 @@ impl InlineQueryResultVenue {
} }
#[must_use] #[must_use]
pub fn thumb_width(mut self, val: i32) -> Self { pub fn thumb_width(mut self, val: u32) -> Self {
self.thumb_width = Some(val); self.thumb_width = Some(val);
self self
} }
#[must_use] #[must_use]
pub fn thumb_height(mut self, val: i32) -> Self { pub fn thumb_height(mut self, val: u32) -> Self {
self.thumb_height = Some(val); self.thumb_height = Some(val);
self self
} }

View file

@ -1,7 +1,7 @@
use mime::Mime; use mime::Mime;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::types::{InlineKeyboardMarkup, InputMessageContent, MessageEntity, ParseMode}; use crate::types::{InlineKeyboardMarkup, InputMessageContent, MessageEntity, ParseMode, Seconds};
/// Represents a link to a page containing an embedded video player or a video /// Represents a link to a page containing an embedded video player or a video
/// file. /// file.
@ -46,13 +46,13 @@ pub struct InlineQueryResultVideo {
pub caption_entities: Option<Vec<MessageEntity>>, pub caption_entities: Option<Vec<MessageEntity>>,
/// Video width. /// Video width.
pub video_width: Option<i32>, pub video_width: Option<u32>,
/// Video height. /// Video height.
pub video_height: Option<i32>, pub video_height: Option<u32>,
/// Video duration in seconds. /// Video duration in seconds.
pub video_duration: Option<i32>, pub video_duration: Option<Seconds>,
/// Short description of the result. /// Short description of the result.
pub description: Option<String>, pub description: Option<String>,
@ -158,19 +158,19 @@ impl InlineQueryResultVideo {
} }
#[must_use] #[must_use]
pub fn video_width(mut self, val: i32) -> Self { pub fn video_width(mut self, val: u32) -> Self {
self.video_width = Some(val); self.video_width = Some(val);
self self
} }
#[must_use] #[must_use]
pub fn video_height(mut self, val: i32) -> Self { pub fn video_height(mut self, val: u32) -> Self {
self.video_height = Some(val); self.video_height = Some(val);
self self
} }
#[must_use] #[must_use]
pub fn video_duration(mut self, val: i32) -> Self { pub fn video_duration(mut self, val: Seconds) -> Self {
self.video_duration = Some(val); self.video_duration = Some(val);
self self
} }

View file

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::types::{InlineKeyboardMarkup, InputMessageContent, MessageEntity, ParseMode}; use crate::types::{InlineKeyboardMarkup, InputMessageContent, MessageEntity, ParseMode, Seconds};
/// Represents a link to a voice recording in an .ogg container encoded with /// Represents a link to a voice recording in an .ogg container encoded with
/// OPUS. /// OPUS.
@ -38,7 +38,7 @@ pub struct InlineQueryResultVoice {
pub caption_entities: Option<Vec<MessageEntity>>, pub caption_entities: Option<Vec<MessageEntity>>,
/// Recording duration in seconds. /// Recording duration in seconds.
pub voice_duration: Option<i32>, pub voice_duration: Option<Seconds>,
/// [Inline keyboard] attached to the message. /// [Inline keyboard] attached to the message.
/// ///
@ -113,7 +113,7 @@ impl InlineQueryResultVoice {
} }
#[must_use] #[must_use]
pub fn voice_duration(mut self, value: i32) -> Self { pub fn voice_duration(mut self, value: Seconds) -> Self {
self.voice_duration = Some(value); self.voice_duration = Some(value);
self self
} }