From 6f3aa993afcdcccad59b903a1e907961b4d3416b Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Sun, 7 Aug 2022 22:47:20 +0400 Subject: [PATCH 1/3] Add `#[must_use]`s --- src/adaptors/throttle/settings.rs | 1 + src/bot.rs | 4 ++ src/net.rs | 1 + src/types/chat.rs | 22 +++++++ src/types/chat_id.rs | 3 + src/types/chat_member.rs | 38 ++++++++++++ src/types/force_reply.rs | 2 + src/types/inline_keyboard_button.rs | 1 + src/types/inline_keyboard_markup.rs | 1 + src/types/inline_query.rs | 2 + src/types/inline_query_result_article.rs | 7 +++ src/types/inline_query_result_audio.rs | 4 ++ src/types/inline_query_result_cached_audio.rs | 3 + .../inline_query_result_cached_document.rs | 3 + src/types/inline_query_result_cached_gif.rs | 3 + .../inline_query_result_cached_mpeg4_gif.rs | 3 + src/types/inline_query_result_cached_photo.rs | 3 + .../inline_query_result_cached_sticker.rs | 2 + src/types/inline_query_result_cached_video.rs | 3 + src/types/inline_query_result_cached_voice.rs | 3 + src/types/inline_query_result_contact.rs | 5 ++ src/types/inline_query_result_document.rs | 8 +++ src/types/inline_query_result_game.rs | 1 + src/types/inline_query_result_gif.rs | 8 +++ src/types/inline_query_result_location.rs | 11 ++++ src/types/inline_query_result_mpeg4_gif.rs | 8 +++ src/types/inline_query_result_photo.rs | 7 +++ src/types/inline_query_result_venue.rs | 7 +++ src/types/inline_query_result_video.rs | 9 +++ src/types/inline_query_result_voice.rs | 5 ++ src/types/input_file.rs | 1 + src/types/input_message_content.rs | 21 +++++++ src/types/label_price.rs | 1 + src/types/login_url.rs | 2 + src/types/mask_position.rs | 3 + src/types/me.rs | 3 + src/types/message.rs | 61 +++++++++++++++++++ src/types/message_entity.rs | 22 +++++++ src/types/passport_element_error.rs | 10 +++ src/types/reply_keyboard_markup.rs | 1 + src/types/reply_keyboard_remove.rs | 2 + src/types/reply_markup.rs | 2 + src/types/sticker.rs | 3 + src/types/update.rs | 2 + src/types/user.rs | 8 +++ src/types/user_id.rs | 4 ++ 46 files changed, 324 insertions(+) diff --git a/src/adaptors/throttle/settings.rs b/src/adaptors/throttle/settings.rs index 289f5b42..57b38e9a 100644 --- a/src/adaptors/throttle/settings.rs +++ b/src/adaptors/throttle/settings.rs @@ -21,6 +21,7 @@ type BoxedFuture = Pin + Send>>; /// ``` /// /// [`Throttle`]: crate::adaptors::throttle::Throttle +#[must_use] #[non_exhaustive] pub struct Settings { pub limits: Limits, diff --git a/src/bot.rs b/src/bot.rs index 0b7cb67e..2b3f6893 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -51,6 +51,7 @@ const TELOXIDE_TOKEN: &str = "TELOXIDE_TOKEN"; /// /// [`Arc`]: std::sync::Arc /// [Telegram Bot API]: https://core.telegram.org/bots/api +#[must_use] #[derive(Debug, Clone)] pub struct Bot { token: Arc, @@ -186,16 +187,19 @@ impl Bot { /// Getters impl Bot { /// Returns currently used token. + #[must_use] pub fn token(&self) -> &str { &self.token } /// Returns currently used http-client. + #[must_use] pub fn client(&self) -> &Client { &self.client } /// Returns currently used token API url. + #[must_use] pub fn api_url(&self) -> reqwest::Url { reqwest::Url::clone(&*self.api_url) } diff --git a/src/net.rs b/src/net.rs index 75b41dad..4f76fdb1 100644 --- a/src/net.rs +++ b/src/net.rs @@ -34,6 +34,7 @@ pub const TELEGRAM_API_URL: &str = "https://api.telegram.org"; /// ## Panics /// /// If `TELOXIDE_PROXY` exists, but isn't correct url. +#[must_use] pub fn client_from_env() -> reqwest::Client { use reqwest::Proxy; diff --git a/src/types/chat.rs b/src/types/chat.rs index fc0314c3..6131b87d 100644 --- a/src/types/chat.rs +++ b/src/types/chat.rs @@ -191,10 +191,12 @@ pub struct PublicChatSupergroup { } impl Chat { + #[must_use] pub fn is_private(&self) -> bool { matches!(self.kind, ChatKind::Private(_)) } + #[must_use] pub fn is_group(&self) -> bool { matches!( self.kind, @@ -205,6 +207,7 @@ impl Chat { ) } + #[must_use] pub fn is_supergroup(&self) -> bool { matches!( self.kind, @@ -215,6 +218,7 @@ impl Chat { ) } + #[must_use] pub fn is_channel(&self) -> bool { matches!( self.kind, @@ -225,6 +229,7 @@ impl Chat { ) } + #[must_use] pub fn is_chat(&self) -> bool { self.is_private() || self.is_group() || self.is_supergroup() } @@ -233,6 +238,7 @@ impl Chat { /// Getters impl Chat { /// A title, for supergroups, channels and group chats. + #[must_use] pub fn title(&self) -> Option<&str> { match &self.kind { ChatKind::Public(this) => this.title.as_deref(), @@ -241,6 +247,7 @@ impl Chat { } /// A username, for private chats, supergroups and channels if available. + #[must_use] pub fn username(&self) -> Option<&str> { match &self.kind { ChatKind::Public(this) => match &this.kind { @@ -258,6 +265,7 @@ impl Chat { /// identifier for a channel and vice versa. Returned only in [`GetChat`]. /// /// [`GetChat`]: crate::payloads::GetChat + #[must_use] pub fn linked_chat_id(&self) -> Option { match &self.kind { ChatKind::Public(this) => match &this.kind { @@ -275,6 +283,7 @@ impl Chat { /// only from [`GetChat`]. /// /// [`GetChat`]: crate::payloads::GetChat + #[must_use] pub fn permissions(&self) -> Option { if let ChatKind::Public(this) = &self.kind { if let PublicChatKind::Group(PublicChatGroup { permissions }) @@ -291,6 +300,7 @@ impl Chat { /// [`GetChat`]. /// /// [`GetChat`]: crate::payloads::GetChat + #[must_use] pub fn sticker_set_name(&self) -> Option<&str> { if let ChatKind::Public(this) = &self.kind { if let PublicChatKind::Supergroup(this) = &this.kind { @@ -305,6 +315,7 @@ impl Chat { /// from [`GetChat`]. /// /// [`GetChat`]: crate::payloads::GetChat + #[must_use] pub fn can_set_sticker_set(&self) -> Option { if let ChatKind::Public(this) = &self.kind { if let PublicChatKind::Supergroup(this) = &this.kind { @@ -319,6 +330,7 @@ impl Chat { /// unpriviledged user. Returned only from [`GetChat`]. /// /// [`GetChat`]: crate::payloads::GetChat + #[must_use] pub fn slow_mode_delay(&self) -> Option { if let ChatKind::Public(this) = &self.kind { if let PublicChatKind::Supergroup(this) = &this.kind { @@ -333,6 +345,7 @@ impl Chat { /// [`GetChat`]. /// /// [`GetChat`]: crate::payloads::GetChat + #[must_use] pub fn location(&self) -> Option<&ChatLocation> { if let ChatKind::Public(this) = &self.kind { if let PublicChatKind::Supergroup(this) = &this.kind { @@ -347,6 +360,7 @@ impl Chat { /// messages. Returned only in [`GetChat`]. /// /// [`GetChat`]: crate::payloads::GetChat + #[must_use] pub fn join_to_send_messages(&self) -> Option { if let ChatKind::Public(this) = &self.kind { if let PublicChatKind::Supergroup(this) = &this.kind { @@ -361,6 +375,7 @@ impl Chat { /// by supergroup administrators. Returned only in [`GetChat`]. /// /// [`GetChat`]: crate::payloads::GetChat + #[must_use] pub fn join_by_request(&self) -> Option { if let ChatKind::Public(this) = &self.kind { if let PublicChatKind::Supergroup(this) = &this.kind { @@ -375,6 +390,7 @@ impl Chat { /// only in [`GetChat`]. /// /// [`GetChat`]: crate::payloads::GetChat + #[must_use] pub fn description(&self) -> Option<&str> { match &self.kind { ChatKind::Public(this) => this.description.as_deref(), @@ -392,6 +408,7 @@ impl Chat { /// crate::payloads::ExportChatInviteLink /// /// [`GetChat`]: crate::payloads::GetChat + #[must_use] pub fn invite_link(&self) -> Option<&str> { match &self.kind { ChatKind::Public(this) => this.invite_link.as_deref(), @@ -403,6 +420,7 @@ impl Chat { /// Returned only in [`GetChat`]. /// /// [`GetChat`]: crate::payloads::GetChat + #[must_use] pub fn has_protected_content(&self) -> Option { match &self.kind { ChatKind::Public(this) => this.has_protected_content, @@ -411,6 +429,7 @@ impl Chat { } /// A first name of the other party in a private chat. + #[must_use] pub fn first_name(&self) -> Option<&str> { match &self.kind { ChatKind::Private(this) => this.first_name.as_deref(), @@ -419,6 +438,7 @@ impl Chat { } /// A last name of the other party in a private chat. + #[must_use] pub fn last_name(&self) -> Option<&str> { match &self.kind { ChatKind::Private(this) => this.last_name.as_deref(), @@ -429,6 +449,7 @@ impl Chat { /// Bio of the other party in a private chat. Returned only in [`GetChat`]. /// /// [`GetChat`]: crate::payloads::GetChat + #[must_use] pub fn bio(&self) -> Option<&str> { match &self.kind { ChatKind::Private(this) => this.bio.as_deref(), @@ -441,6 +462,7 @@ impl Chat { /// user. Returned only in [`GetChat`]. /// /// [`GetChat`]: crate::payloads::GetChat + #[must_use] pub fn has_private_forwards(&self) -> Option { match &self.kind { ChatKind::Private(this) => this.has_private_forwards, diff --git a/src/types/chat_id.rs b/src/types/chat_id.rs index cca06e41..a7a53224 100644 --- a/src/types/chat_id.rs +++ b/src/types/chat_id.rs @@ -31,6 +31,7 @@ pub(crate) enum BareChatId { impl ChatId { /// Returns `true` if this is an id of a user. + #[must_use] pub fn is_user(self) -> bool { matches!(self.to_bare(), BareChatId::User(_)) } @@ -38,11 +39,13 @@ impl ChatId { /// Returns `true` if this is an id of a group. /// /// Note: supergroup is **not** considered a group. + #[must_use] pub fn is_group(self) -> bool { matches!(self.to_bare(), BareChatId::Group(_)) } /// Returns `true` if this is an id of a channel. + #[must_use] pub fn is_channel_or_supergroup(self) -> bool { matches!(self.to_bare(), BareChatId::Channel(_)) } diff --git a/src/types/chat_member.rs b/src/types/chat_member.rs index 7ddc7a77..affed635 100644 --- a/src/types/chat_member.rs +++ b/src/types/chat_member.rs @@ -147,6 +147,7 @@ impl Deref for ChatMember { /// Simple methods for checking a user status. impl ChatMemberKind { /// Returns chat member status. + #[must_use] pub fn status(&self) -> ChatMemberStatus { match self { ChatMemberKind::Owner(_) => ChatMemberStatus::Owner, @@ -161,6 +162,7 @@ impl ChatMemberKind { /// Returns `true` if the user is the [owner] of the given chat. /// /// [owner]: ChatMemberKind::Owner + #[must_use] pub fn is_owner(&self) -> bool { matches!(self, Self::Owner { .. }) } @@ -173,6 +175,7 @@ impl ChatMemberKind { /// owner of the given chat. See also: [`is_privileged`]. /// /// [`is_privileged`]: ChatMemberKind::is_privileged + #[must_use] pub fn is_administrator(&self) -> bool { matches!(self, Self::Administrator { .. }) } @@ -180,6 +183,7 @@ impl ChatMemberKind { /// Returns `true` if the user is a common [member] of the given chat. /// /// [member]: ChatMemberKind::Member + #[must_use] pub fn is_member(&self) -> bool { matches!(self, Self::Member { .. }) } @@ -187,6 +191,7 @@ impl ChatMemberKind { /// Returns `true` if the user is [restricted] in the given chat. /// /// [restricted]: ChatMemberKind::Restricted + #[must_use] pub fn is_restricted(&self) -> bool { matches!(self, Self::Restricted { .. }) } @@ -194,6 +199,7 @@ impl ChatMemberKind { /// Returns `true` if the user [left] the given chat. /// /// [left]: ChatMemberKind::Left + #[must_use] pub fn is_left(&self) -> bool { matches!(self, Self::Left { .. }) } @@ -201,6 +207,7 @@ impl ChatMemberKind { /// Returns `true` if the user is [banned] in the given chat. /// /// [banned]: ChatMemberKind::Banned + #[must_use] pub fn is_banned(&self) -> bool { matches!(self, Self::Banned { .. }) } @@ -209,6 +216,7 @@ impl ChatMemberKind { /// /// [kicked]: ChatMemberKind::Banned #[deprecated = "use `is_banned` instead"] + #[must_use] pub fn is_kicked(&self) -> bool { self.is_banned() } @@ -217,6 +225,7 @@ impl ChatMemberKind { /// /// [creator]: ChatMemberKind::Owner #[deprecated = "use `is_owner` instead"] + #[must_use] pub fn is_creator(&self) -> bool { self.is_owner() } @@ -229,6 +238,7 @@ impl ChatMemberKind { /// /// [owner]: ChatMemberKind::Owner /// [administrator]: ChatMemberKind::Administrator + #[must_use] pub fn is_privileged(&self) -> bool { self.is_administrator() || self.is_owner() } @@ -238,6 +248,7 @@ impl ChatMemberKind { /// /// [left]: ChatMemberKind::Left /// [banned]: ChatMemberKind::Banned + #[must_use] pub fn is_present(&self) -> bool { !(self.is_left() || self.is_banned()) } @@ -246,6 +257,7 @@ impl ChatMemberKind { impl ChatMemberKind { /// Getter for [`Administrator::custom_title`] and [`Owner::custom_title`] /// fields. + #[must_use] pub fn custom_title(&self) -> Option<&str> { match &self { Self::Administrator(Administrator { custom_title, .. }) @@ -261,6 +273,7 @@ impl ChatMemberKind { /// Returns `false` otherwise. /// /// [`can_manage_chat`]: Administrator::can_manage_chat + #[must_use] pub fn is_anonymous(&self) -> bool { match self { Self::Owner(Owner { is_anonymous, .. }) @@ -270,6 +283,7 @@ impl ChatMemberKind { } /// Getter for [`Restricted::until_date`] and [`Banned::until_date`] fields. + #[must_use] pub fn until_date(&self) -> Option { match &self { Self::Owner(_) | Self::Administrator(_) | Self::Member | Self::Left => None, @@ -283,6 +297,7 @@ impl ChatMemberKind { impl ChatMemberKind { /// Returns `true` if the user is an administrator in the given chat and the /// bot is allowed to edit administrator privileges of that user. + #[must_use] pub fn can_be_edited(&self) -> bool { match self { Self::Administrator(Administrator { can_be_edited, .. }) => *can_be_edited, @@ -305,6 +320,7 @@ impl ChatMemberKind { /// Returns `false` otherwise. /// /// [`can_manage_chat`]: Administrator::can_manage_chat + #[must_use] pub fn can_manage_chat(&self) -> bool { match self { Self::Owner(_) => true, @@ -325,6 +341,7 @@ impl ChatMemberKind { /// Returns `false` otherwise. /// /// [`can_change_info`]: Administrator::can_change_info + #[must_use] pub fn can_change_info(&self) -> bool { match self { Self::Owner(_) => true, @@ -344,6 +361,7 @@ impl ChatMemberKind { /// Returns `false` otherwise. /// /// [`can_post_messages`]: Administrator::can_post_messages + #[must_use] pub fn can_post_messages(&self) -> bool { match self { Self::Owner(_) => true, @@ -364,6 +382,7 @@ impl ChatMemberKind { /// Returns `false` otherwise. /// /// [`can_edit_messages`]: Administrator::can_edit_messages + #[must_use] pub fn can_edit_messages(&self) -> bool { match self { Self::Owner(_) => true, @@ -383,6 +402,7 @@ impl ChatMemberKind { /// Returns `false` otherwise. /// /// [`can_delete_messages`]: Administrator::can_delete_messages + #[must_use] pub fn can_delete_messages(&self) -> bool { match self { Self::Owner(_) => true, @@ -403,6 +423,7 @@ impl ChatMemberKind { /// Returns `false` otherwise. /// /// [`can_manage_video_chats`]: Administrator::can_manage_video_chats + #[must_use] pub fn can_manage_video_chats(&self) -> bool { match self { Self::Owner(_) => true, @@ -415,6 +436,7 @@ impl ChatMemberKind { } #[deprecated(since = "0.6.0", note = "renamed to `can_manage_video_chats`")] + #[must_use] pub fn can_manage_voice_chats(&self) -> bool { self.can_manage_video_chats() } @@ -428,6 +450,7 @@ impl ChatMemberKind { /// Returns `false` otherwise. /// /// [`can_invite_users`]: Administrator::can_invite_users + #[must_use] pub fn can_invite_users(&self) -> bool { match &self { Self::Owner(_) => true, @@ -447,6 +470,7 @@ impl ChatMemberKind { /// Returns `false` otherwise. /// /// [`can_restrict_members`]: Administrator::can_restrict_members + #[must_use] pub fn can_restrict_members(&self) -> bool { match self { Self::Owner(_) => true, @@ -467,6 +491,7 @@ impl ChatMemberKind { /// Returns `false` otherwise. /// /// [`can_pin_messages`]: Administrator::can_pin_messages + #[must_use] pub fn can_pin_messages(&self) -> bool { match self { Self::Owner(_) => true, @@ -489,6 +514,7 @@ impl ChatMemberKind { /// Returns `false` otherwise. /// /// [`can_promote_members`]: Administrator::can_promote_members + #[must_use] pub fn can_promote_members(&self) -> bool { match self { Self::Owner(_) => true, @@ -512,6 +538,7 @@ impl ChatMemberKind { /// Returns `true` otherwise. /// /// [`can_send_messages`]: Restricted::can_send_messages + #[must_use] pub fn can_send_messages(&self) -> bool { match &self { Self::Restricted(Restricted { @@ -531,6 +558,7 @@ impl ChatMemberKind { /// Returns `true` otherwise. /// /// [`can_send_media_messages`]: Restricted::can_send_media_messages + #[must_use] pub fn can_send_media_messages(&self) -> bool { match &self { Self::Restricted(Restricted { @@ -551,6 +579,7 @@ impl ChatMemberKind { /// Returns `true` otherwise. /// /// [`can_send_media_messages`]: Restricted::can_send_media_messages + #[must_use] pub fn can_send_other_messages(&self) -> bool { match &self { Self::Restricted(Restricted { @@ -571,6 +600,7 @@ impl ChatMemberKind { /// Returns `true` otherwise. /// /// [`can_send_media_messages`]: Restricted::can_send_media_messages + #[must_use] pub fn can_add_web_page_previews(&self) -> bool { match &self { Self::Restricted(Restricted { @@ -601,6 +631,7 @@ impl ChatMemberStatus { /// Returns `true` if the user is the [owner] of the given chat. /// /// [owner]: ChatMemberKind::Owner + #[must_use] pub fn is_owner(&self) -> bool { matches!(self, Self::Owner { .. }) } @@ -613,6 +644,7 @@ impl ChatMemberStatus { /// owner of the given chat. See also: [`is_privileged`]. /// /// [`is_privileged`]: ChatMemberKind::is_privileged + #[must_use] pub fn is_administrator(&self) -> bool { matches!(self, Self::Administrator { .. }) } @@ -620,6 +652,7 @@ impl ChatMemberStatus { /// Returns `true` if the user is a common [member] of the given chat. /// /// [member]: ChatMemberKind::Member + #[must_use] pub fn is_member(&self) -> bool { matches!(self, Self::Member { .. }) } @@ -627,6 +660,7 @@ impl ChatMemberStatus { /// Returns `true` if the user is [restricted] in the given chat. /// /// [restricted]: ChatMemberKind::Restricted + #[must_use] pub fn is_restricted(&self) -> bool { matches!(self, Self::Restricted { .. }) } @@ -634,6 +668,7 @@ impl ChatMemberStatus { /// Returns `true` if the user [left] the given chat. /// /// [left]: ChatMemberKind::Left + #[must_use] pub fn is_left(&self) -> bool { matches!(self, Self::Left { .. }) } @@ -641,6 +676,7 @@ impl ChatMemberStatus { /// Returns `true` if the user is [banned] in the given chat. /// /// [banned]: ChatMemberKind::Banned + #[must_use] pub fn is_banned(&self) -> bool { matches!(self, Self::Banned { .. }) } @@ -653,6 +689,7 @@ impl ChatMemberStatus { /// /// [owner]: ChatMemberKind::Owner /// [administrator]: ChatMemberKind::Administrator + #[must_use] pub fn is_privileged(&self) -> bool { self.is_administrator() || self.is_owner() } @@ -662,6 +699,7 @@ impl ChatMemberStatus { /// /// [left]: ChatMemberKind::Left /// [banned]: ChatMemberKind::Banned + #[must_use] pub fn is_present(&self) -> bool { !(self.is_left() || self.is_banned()) } diff --git a/src/types/force_reply.rs b/src/types/force_reply.rs index b641fc99..471a55a6 100644 --- a/src/types/force_reply.rs +++ b/src/types/force_reply.rs @@ -33,6 +33,7 @@ pub struct ForceReply { } impl ForceReply { + #[must_use] pub const fn new() -> Self { Self { force_reply: True, @@ -49,6 +50,7 @@ impl ForceReply { self } + #[must_use] pub const fn selective(mut self, val: bool) -> Self { self.selective = Some(val); self diff --git a/src/types/inline_keyboard_button.rs b/src/types/inline_keyboard_button.rs index 59282fac..651f8931 100644 --- a/src/types/inline_keyboard_button.rs +++ b/src/types/inline_keyboard_button.rs @@ -218,6 +218,7 @@ impl InlineKeyboardButton { since = "0.7.0", note = "set correct kind in the constructor or access the field directly" )] + #[must_use] pub fn kind(mut self, val: InlineKeyboardButtonKind) -> Self { self.kind = val; self diff --git a/src/types/inline_keyboard_markup.rs b/src/types/inline_keyboard_markup.rs index 21365f4f..f0c61fd1 100644 --- a/src/types/inline_keyboard_markup.rs +++ b/src/types/inline_keyboard_markup.rs @@ -66,6 +66,7 @@ impl InlineKeyboardMarkup { self } + #[must_use] pub fn append_to_row(mut self, index: usize, button: InlineKeyboardButton) -> Self { match self.inline_keyboard.get_mut(index) { Some(buttons) => buttons.push(button), diff --git a/src/types/inline_query.rs b/src/types/inline_query.rs index 8089cd54..41f687c7 100644 --- a/src/types/inline_query.rs +++ b/src/types/inline_query.rs @@ -60,11 +60,13 @@ impl InlineQuery { self } + #[must_use] pub fn from(mut self, val: User) -> Self { self.from = val; self } + #[must_use] pub fn location(mut self, val: Location) -> Self { self.location = Some(val); self diff --git a/src/types/inline_query_result_article.rs b/src/types/inline_query_result_article.rs index 2ec6daf3..5e0d3be9 100644 --- a/src/types/inline_query_result_article.rs +++ b/src/types/inline_query_result_article.rs @@ -76,21 +76,25 @@ impl InlineQueryResultArticle { self } + #[must_use] pub fn input_message_content(mut self, val: InputMessageContent) -> Self { self.input_message_content = val; self } + #[must_use] pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { self.reply_markup = Some(val); self } + #[must_use] pub fn url(mut self, val: reqwest::Url) -> Self { self.url = Some(val); self } + #[must_use] pub fn hide_url(mut self, val: bool) -> Self { self.hide_url = Some(val); self @@ -104,16 +108,19 @@ impl InlineQueryResultArticle { self } + #[must_use] pub fn thumb_url(mut self, val: reqwest::Url) -> Self { self.thumb_url = Some(val); self } + #[must_use] pub fn thumb_width(mut self, val: i32) -> Self { self.thumb_width = Some(val); self } + #[must_use] pub fn thumb_height(mut self, val: i32) -> Self { self.thumb_height = Some(val); self diff --git a/src/types/inline_query_result_audio.rs b/src/types/inline_query_result_audio.rs index 9e2fbd99..7fa9e988 100644 --- a/src/types/inline_query_result_audio.rs +++ b/src/types/inline_query_result_audio.rs @@ -79,6 +79,7 @@ impl InlineQueryResultAudio { self } + #[must_use] pub fn audio_url(mut self, val: reqwest::Url) -> Self { self.audio_url = val; self @@ -100,6 +101,7 @@ impl InlineQueryResultAudio { self } + #[must_use] pub fn parse_mode(mut self, val: ParseMode) -> Self { self.parse_mode = Some(val); self @@ -129,11 +131,13 @@ impl InlineQueryResultAudio { self } + #[must_use] pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { self.reply_markup = Some(val); self } + #[must_use] pub fn input_message_content(mut self, val: InputMessageContent) -> Self { self.input_message_content = Some(val); self diff --git a/src/types/inline_query_result_cached_audio.rs b/src/types/inline_query_result_cached_audio.rs index e74c3954..cb5463b8 100644 --- a/src/types/inline_query_result_cached_audio.rs +++ b/src/types/inline_query_result_cached_audio.rs @@ -83,6 +83,7 @@ impl InlineQueryResultCachedAudio { self } + #[must_use] pub fn parse_mode(mut self, val: ParseMode) -> Self { self.parse_mode = Some(val); self @@ -96,11 +97,13 @@ impl InlineQueryResultCachedAudio { self } + #[must_use] pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { self.reply_markup = Some(val); self } + #[must_use] pub fn input_message_content(mut self, val: InputMessageContent) -> Self { self.input_message_content = Some(val); self diff --git a/src/types/inline_query_result_cached_document.rs b/src/types/inline_query_result_cached_document.rs index 79de0b16..104ca26b 100644 --- a/src/types/inline_query_result_cached_document.rs +++ b/src/types/inline_query_result_cached_document.rs @@ -108,6 +108,7 @@ impl InlineQueryResultCachedDocument { self } + #[must_use] pub fn parse_mode(mut self, val: ParseMode) -> Self { self.parse_mode = Some(val); self @@ -121,11 +122,13 @@ impl InlineQueryResultCachedDocument { self } + #[must_use] pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { self.reply_markup = Some(val); self } + #[must_use] pub fn input_message_content(mut self, val: InputMessageContent) -> Self { self.input_message_content = Some(val); self diff --git a/src/types/inline_query_result_cached_gif.rs b/src/types/inline_query_result_cached_gif.rs index cc51a823..889096c9 100644 --- a/src/types/inline_query_result_cached_gif.rs +++ b/src/types/inline_query_result_cached_gif.rs @@ -96,6 +96,7 @@ impl InlineQueryResultCachedGif { self } + #[must_use] pub fn parse_mode(mut self, val: ParseMode) -> Self { self.parse_mode = Some(val); self @@ -109,11 +110,13 @@ impl InlineQueryResultCachedGif { self } + #[must_use] pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { self.reply_markup = Some(val); self } + #[must_use] pub fn input_message_content(mut self, val: InputMessageContent) -> Self { self.input_message_content = Some(val); self diff --git a/src/types/inline_query_result_cached_mpeg4_gif.rs b/src/types/inline_query_result_cached_mpeg4_gif.rs index 05ccb521..26dbfd5d 100644 --- a/src/types/inline_query_result_cached_mpeg4_gif.rs +++ b/src/types/inline_query_result_cached_mpeg4_gif.rs @@ -88,6 +88,7 @@ impl InlineQueryResultCachedMpeg4Gif { self } + #[must_use] pub fn parse_mode(mut self, val: ParseMode) -> Self { self.parse_mode = Some(val); self @@ -101,11 +102,13 @@ impl InlineQueryResultCachedMpeg4Gif { self } + #[must_use] pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { self.reply_markup = Some(val); self } + #[must_use] pub fn input_message_content(mut self, val: InputMessageContent) -> Self { self.input_message_content = Some(val); self diff --git a/src/types/inline_query_result_cached_photo.rs b/src/types/inline_query_result_cached_photo.rs index 2a9c2bad..fda7e735 100644 --- a/src/types/inline_query_result_cached_photo.rs +++ b/src/types/inline_query_result_cached_photo.rs @@ -107,6 +107,7 @@ impl InlineQueryResultCachedPhoto { self } + #[must_use] pub fn parse_mode(mut self, val: ParseMode) -> Self { self.parse_mode = Some(val); self @@ -120,11 +121,13 @@ impl InlineQueryResultCachedPhoto { self } + #[must_use] pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { self.reply_markup = Some(val); self } + #[must_use] pub fn input_message_content(mut self, val: InputMessageContent) -> Self { self.input_message_content = Some(val); self diff --git a/src/types/inline_query_result_cached_sticker.rs b/src/types/inline_query_result_cached_sticker.rs index 66c4138f..ab3ac3d2 100644 --- a/src/types/inline_query_result_cached_sticker.rs +++ b/src/types/inline_query_result_cached_sticker.rs @@ -57,11 +57,13 @@ impl InlineQueryResultCachedSticker { self } + #[must_use] pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { self.reply_markup = Some(val); self } + #[must_use] pub fn input_message_content(mut self, val: InputMessageContent) -> Self { self.input_message_content = Some(val); self diff --git a/src/types/inline_query_result_cached_video.rs b/src/types/inline_query_result_cached_video.rs index 50bad2c0..35c38f57 100644 --- a/src/types/inline_query_result_cached_video.rs +++ b/src/types/inline_query_result_cached_video.rs @@ -108,6 +108,7 @@ impl InlineQueryResultCachedVideo { self } + #[must_use] pub fn parse_mode(mut self, val: ParseMode) -> Self { self.parse_mode = Some(val); self @@ -121,11 +122,13 @@ impl InlineQueryResultCachedVideo { self } + #[must_use] pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { self.reply_markup = Some(val); self } + #[must_use] pub fn input_message_content(mut self, val: InputMessageContent) -> Self { self.input_message_content = Some(val); self diff --git a/src/types/inline_query_result_cached_voice.rs b/src/types/inline_query_result_cached_voice.rs index 50733059..90f002df 100644 --- a/src/types/inline_query_result_cached_voice.rs +++ b/src/types/inline_query_result_cached_voice.rs @@ -96,6 +96,7 @@ impl InlineQueryResultCachedVoice { self } + #[must_use] pub fn parse_mode(mut self, val: ParseMode) -> Self { self.parse_mode = Some(val); self @@ -109,11 +110,13 @@ impl InlineQueryResultCachedVoice { self } + #[must_use] pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { self.reply_markup = Some(val); self } + #[must_use] pub fn input_message_content(mut self, val: InputMessageContent) -> Self { self.input_message_content = Some(val); self diff --git a/src/types/inline_query_result_contact.rs b/src/types/inline_query_result_contact.rs index 8b41f239..16ae652b 100644 --- a/src/types/inline_query_result_contact.rs +++ b/src/types/inline_query_result_contact.rs @@ -109,26 +109,31 @@ impl InlineQueryResultContact { self } + #[must_use] pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { self.reply_markup = Some(val); self } + #[must_use] pub fn input_message_content(mut self, val: InputMessageContent) -> Self { self.input_message_content = Some(val); self } + #[must_use] pub fn thumb_url(mut self, val: reqwest::Url) -> Self { self.thumb_url = Some(val); self } + #[must_use] pub fn thumb_width(mut self, val: i32) -> Self { self.thumb_width = Some(val); self } + #[must_use] pub fn thumb_height(mut self, val: i32) -> Self { self.thumb_height = Some(val); self diff --git a/src/types/inline_query_result_document.rs b/src/types/inline_query_result_document.rs index 959469b1..329f411d 100644 --- a/src/types/inline_query_result_document.rs +++ b/src/types/inline_query_result_document.rs @@ -87,6 +87,7 @@ impl InlineQueryResultDocument { self } + #[must_use] pub fn parse_mode(mut self, val: ParseMode) -> Self { self.parse_mode = Some(val); self @@ -100,11 +101,13 @@ impl InlineQueryResultDocument { self } + #[must_use] pub fn document_url(mut self, val: reqwest::Url) -> Self { self.document_url = val; self } + #[must_use] pub fn mime_type(mut self, val: Mime) -> Self { self.mime_type = val; self @@ -118,26 +121,31 @@ impl InlineQueryResultDocument { self } + #[must_use] pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { self.reply_markup = Some(val); self } + #[must_use] pub fn input_message_content(mut self, val: InputMessageContent) -> Self { self.input_message_content = Some(val); self } + #[must_use] pub fn thumb_url(mut self, val: reqwest::Url) -> Self { self.thumb_url = Some(val); self } + #[must_use] pub fn thumb_width(mut self, val: i32) -> Self { self.thumb_width = Some(val); self } + #[must_use] pub fn thumb_height(mut self, val: i32) -> Self { self.thumb_height = Some(val); self diff --git a/src/types/inline_query_result_game.rs b/src/types/inline_query_result_game.rs index 9e6c074e..68d01a2e 100644 --- a/src/types/inline_query_result_game.rs +++ b/src/types/inline_query_result_game.rs @@ -51,6 +51,7 @@ impl InlineQueryResultGame { self } + #[must_use] pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { self.reply_markup = Some(val); self diff --git a/src/types/inline_query_result_gif.rs b/src/types/inline_query_result_gif.rs index 0154bbf2..8c1200f2 100644 --- a/src/types/inline_query_result_gif.rs +++ b/src/types/inline_query_result_gif.rs @@ -86,26 +86,31 @@ impl InlineQueryResultGif { self } + #[must_use] pub fn gif_url(mut self, val: reqwest::Url) -> Self { self.gif_url = val; self } + #[must_use] pub fn gif_width(mut self, val: i32) -> Self { self.gif_width = Some(val); self } + #[must_use] pub fn gif_height(mut self, val: i32) -> Self { self.gif_height = Some(val); self } + #[must_use] pub fn gif_duration(mut self, val: i32) -> Self { self.gif_duration = Some(val); self } + #[must_use] pub fn thumb_url(mut self, val: reqwest::Url) -> Self { self.thumb_url = val; self @@ -127,6 +132,7 @@ impl InlineQueryResultGif { self } + #[must_use] pub fn parse_mode(mut self, val: ParseMode) -> Self { self.parse_mode = Some(val); self @@ -140,11 +146,13 @@ impl InlineQueryResultGif { self } + #[must_use] pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { self.reply_markup = Some(val); self } + #[must_use] pub fn input_message_content(mut self, val: InputMessageContent) -> Self { self.input_message_content = Some(val); self diff --git a/src/types/inline_query_result_location.rs b/src/types/inline_query_result_location.rs index 1ecb1dc5..aa8d6a66 100644 --- a/src/types/inline_query_result_location.rs +++ b/src/types/inline_query_result_location.rs @@ -89,11 +89,13 @@ impl InlineQueryResultLocation { self } + #[must_use] pub fn latitude(mut self, val: f64) -> Self { self.latitude = val; self } + #[must_use] pub fn longitude(mut self, val: f64) -> Self { self.longitude = val; self @@ -107,46 +109,55 @@ impl InlineQueryResultLocation { self } + #[must_use] pub fn horizontal_accuracy(mut self, val: f64) -> Self { self.horizontal_accuracy = Some(val); self } + #[must_use] pub fn live_period(mut self, val: i32) -> Self { self.live_period = Some(val); self } + #[must_use] pub fn heading(mut self, val: u16) -> Self { self.heading = Some(val); self } + #[must_use] pub fn proximity_alert_radius(mut self, val: u32) -> Self { self.proximity_alert_radius = Some(val); self } + #[must_use] pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { self.reply_markup = Some(val); self } + #[must_use] pub fn input_message_content(mut self, val: InputMessageContent) -> Self { self.input_message_content = Some(val); self } + #[must_use] pub fn thumb_url(mut self, val: reqwest::Url) -> Self { self.thumb_url = Some(val); self } + #[must_use] pub fn thumb_width(mut self, val: u32) -> Self { self.thumb_width = Some(val); self } + #[must_use] pub fn thumb_height(mut self, val: u32) -> Self { self.thumb_height = Some(val); self diff --git a/src/types/inline_query_result_mpeg4_gif.rs b/src/types/inline_query_result_mpeg4_gif.rs index 2b700fac..134f38f2 100644 --- a/src/types/inline_query_result_mpeg4_gif.rs +++ b/src/types/inline_query_result_mpeg4_gif.rs @@ -87,26 +87,31 @@ impl InlineQueryResultMpeg4Gif { self } + #[must_use] pub fn mpeg4_url(mut self, val: reqwest::Url) -> Self { self.mpeg4_url = val; self } + #[must_use] pub fn mpeg4_width(mut self, val: i32) -> Self { self.mpeg4_width = Some(val); self } + #[must_use] pub fn mpeg4_height(mut self, val: i32) -> Self { self.mpeg4_height = Some(val); self } + #[must_use] pub fn mpeg4_duration(mut self, val: i32) -> Self { self.mpeg4_duration = Some(val); self } + #[must_use] pub fn thumb_url(mut self, val: reqwest::Url) -> Self { self.thumb_url = val; self @@ -128,6 +133,7 @@ impl InlineQueryResultMpeg4Gif { self } + #[must_use] pub fn parse_mode(mut self, val: ParseMode) -> Self { self.parse_mode = Some(val); self @@ -141,11 +147,13 @@ impl InlineQueryResultMpeg4Gif { self } + #[must_use] pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { self.reply_markup = Some(val); self } + #[must_use] pub fn input_message_content(mut self, val: InputMessageContent) -> Self { self.input_message_content = Some(val); self diff --git a/src/types/inline_query_result_photo.rs b/src/types/inline_query_result_photo.rs index 69cdf7ab..83ca4786 100644 --- a/src/types/inline_query_result_photo.rs +++ b/src/types/inline_query_result_photo.rs @@ -87,21 +87,25 @@ impl InlineQueryResultPhoto { self } + #[must_use] pub fn photo_url(mut self, val: reqwest::Url) -> Self { self.photo_url = val; self } + #[must_use] pub fn thumb_url(mut self, val: reqwest::Url) -> Self { self.thumb_url = val; self } + #[must_use] pub fn photo_width(mut self, val: i32) -> Self { self.photo_width = Some(val); self } + #[must_use] pub fn photo_height(mut self, val: i32) -> Self { self.photo_height = Some(val); self @@ -131,6 +135,7 @@ impl InlineQueryResultPhoto { self } + #[must_use] pub fn parse_mode(mut self, val: ParseMode) -> Self { self.parse_mode = Some(val); self @@ -144,11 +149,13 @@ impl InlineQueryResultPhoto { self } + #[must_use] pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { self.reply_markup = Some(val); self } + #[must_use] pub fn input_message_content(mut self, val: InputMessageContent) -> Self { self.input_message_content = Some(val); self diff --git a/src/types/inline_query_result_venue.rs b/src/types/inline_query_result_venue.rs index 6b6820bf..43f57364 100644 --- a/src/types/inline_query_result_venue.rs +++ b/src/types/inline_query_result_venue.rs @@ -94,11 +94,13 @@ impl InlineQueryResultVenue { self } + #[must_use] pub fn latitude(mut self, val: f64) -> Self { self.latitude = val; self } + #[must_use] pub fn longitude(mut self, val: f64) -> Self { self.longitude = val; self @@ -152,26 +154,31 @@ impl InlineQueryResultVenue { self } + #[must_use] pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { self.reply_markup = Some(val); self } + #[must_use] pub fn input_message_content(mut self, val: InputMessageContent) -> Self { self.input_message_content = Some(val); self } + #[must_use] pub fn thumb_url(mut self, val: reqwest::Url) -> Self { self.thumb_url = Some(val); self } + #[must_use] pub fn thumb_width(mut self, val: i32) -> Self { self.thumb_width = Some(val); self } + #[must_use] pub fn thumb_height(mut self, val: i32) -> Self { self.thumb_height = Some(val); self diff --git a/src/types/inline_query_result_video.rs b/src/types/inline_query_result_video.rs index 51e53a3b..1ece1c8c 100644 --- a/src/types/inline_query_result_video.rs +++ b/src/types/inline_query_result_video.rs @@ -109,16 +109,19 @@ impl InlineQueryResultVideo { self } + #[must_use] pub fn video_url(mut self, val: reqwest::Url) -> Self { self.video_url = val; self } + #[must_use] pub fn mime_type(mut self, val: Mime) -> Self { self.mime_type = val; self } + #[must_use] pub fn thumb_url(mut self, val: reqwest::Url) -> Self { self.thumb_url = val; self @@ -140,6 +143,7 @@ impl InlineQueryResultVideo { self } + #[must_use] pub fn parse_mode(mut self, val: ParseMode) -> Self { self.parse_mode = Some(val); self @@ -153,16 +157,19 @@ impl InlineQueryResultVideo { self } + #[must_use] pub fn video_width(mut self, val: i32) -> Self { self.video_width = Some(val); self } + #[must_use] pub fn video_height(mut self, val: i32) -> Self { self.video_height = Some(val); self } + #[must_use] pub fn video_duration(mut self, val: i32) -> Self { self.video_duration = Some(val); self @@ -176,11 +183,13 @@ impl InlineQueryResultVideo { self } + #[must_use] pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { self.reply_markup = Some(val); self } + #[must_use] pub fn input_message_content(mut self, val: InputMessageContent) -> Self { self.input_message_content = Some(val); self diff --git a/src/types/inline_query_result_voice.rs b/src/types/inline_query_result_voice.rs index 7b9cc1bc..c529ae34 100644 --- a/src/types/inline_query_result_voice.rs +++ b/src/types/inline_query_result_voice.rs @@ -76,6 +76,7 @@ impl InlineQueryResultVoice { self } + #[must_use] pub fn voice_url(mut self, val: reqwest::Url) -> Self { self.voice_url = val; self @@ -97,6 +98,7 @@ impl InlineQueryResultVoice { self } + #[must_use] pub fn parse_mode(mut self, val: ParseMode) -> Self { self.parse_mode = Some(val); self @@ -110,16 +112,19 @@ impl InlineQueryResultVoice { self } + #[must_use] pub fn voice_duration(mut self, value: i32) -> Self { self.voice_duration = Some(value); self } + #[must_use] pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { self.reply_markup = Some(val); self } + #[must_use] pub fn input_message_content(mut self, val: InputMessageContent) -> Self { self.input_message_content = Some(val); self diff --git a/src/types/input_file.rs b/src/types/input_file.rs index f36e5fc0..f0131db5 100644 --- a/src/types/input_file.rs +++ b/src/types/input_file.rs @@ -64,6 +64,7 @@ impl InputFile { /// [`SendAudio`]: crate::payloads::SendAudio /// [`SendDocument`]: crate::payloads::SendDocument /// [`SendVoice`]: crate::payloads::SendVoice + #[must_use] pub fn url(url: url::Url) -> Self { Self::new(Url(url)) } diff --git a/src/types/input_message_content.rs b/src/types/input_message_content.rs index 5ece7563..e41d00f8 100644 --- a/src/types/input_message_content.rs +++ b/src/types/input_message_content.rs @@ -61,6 +61,7 @@ impl InputMessageContentText { self } + #[must_use] pub fn parse_mode(mut self, val: ParseMode) -> Self { self.parse_mode = Some(val); self @@ -74,6 +75,7 @@ impl InputMessageContentText { self } + #[must_use] pub fn disable_web_page_preview(mut self, val: bool) -> Self { self.disable_web_page_preview = Some(val); self @@ -109,6 +111,7 @@ pub struct InputMessageContentLocation { } impl InputMessageContentLocation { + #[must_use] pub const fn new(latitude: f64, longitude: f64) -> Self { Self { latitude, @@ -120,16 +123,19 @@ impl InputMessageContentLocation { } } + #[must_use] pub const fn latitude(mut self, val: f64) -> Self { self.latitude = val; self } + #[must_use] pub const fn longitude(mut self, val: f64) -> Self { self.longitude = val; self } + #[must_use] pub const fn live_period(mut self, val: u32) -> Self { self.live_period = Some(val); self @@ -188,11 +194,13 @@ impl InputMessageContentVenue { } } + #[must_use] pub fn latitude(mut self, val: f64) -> Self { self.latitude = val; self } + #[must_use] pub fn longitude(mut self, val: f64) -> Self { self.longitude = val; self @@ -465,6 +473,7 @@ impl InputMessageContentInvoice { self } + #[must_use] pub fn currency(mut self, val: Currency) -> Self { self.currency = val; self @@ -478,6 +487,7 @@ impl InputMessageContentInvoice { self } + #[must_use] pub fn max_tip_amount(mut self, val: u32) -> Self { self.max_tip_amount = Some(val); self @@ -499,57 +509,68 @@ impl InputMessageContentInvoice { self } + #[must_use] pub fn photo_url(mut self, val: Url) -> Self { self.photo_url = Some(val); self } + #[must_use] pub fn photo_size(mut self, val: u32) -> Self { self.photo_size = Some(val); self } + #[must_use] pub fn photo_width(mut self, val: u32) -> Self { self.photo_width = Some(val); self } + #[must_use] pub fn photo_height(mut self, val: u32) -> Self { self.photo_height = Some(val); self } + #[must_use] pub fn need_name(mut self, val: bool) -> Self { self.need_name = Some(val); self } + #[must_use] pub fn need_phone_number(mut self, val: bool) -> Self { self.need_phone_number = Some(val); self } + #[must_use] pub fn need_email(mut self, val: bool) -> Self { self.need_email = Some(val); self } + #[must_use] pub fn need_shipping_address(mut self, val: bool) -> Self { self.need_shipping_address = Some(val); self } + #[must_use] pub fn send_phone_number_to_provider(mut self, val: bool) -> Self { self.send_phone_number_to_provider = Some(val); self } + #[must_use] pub fn send_email_to_provider(mut self, val: bool) -> Self { self.send_email_to_provider = Some(val); self } #[allow(clippy::wrong_self_convention)] + #[must_use] pub fn is_flexible(mut self, val: bool) -> Self { self.is_flexible = Some(val); self diff --git a/src/types/label_price.rs b/src/types/label_price.rs index 0a5a2f72..33cdd3f4 100644 --- a/src/types/label_price.rs +++ b/src/types/label_price.rs @@ -38,6 +38,7 @@ impl LabeledPrice { self } + #[must_use] pub fn amount(mut self, val: i32) -> Self { self.amount = val; self diff --git a/src/types/login_url.rs b/src/types/login_url.rs index ef8e9a36..dd0146ca 100644 --- a/src/types/login_url.rs +++ b/src/types/login_url.rs @@ -46,6 +46,7 @@ pub struct LoginUrl { } impl LoginUrl { + #[must_use] pub fn url(mut self, val: reqwest::Url) -> Self { self.url = val; self @@ -67,6 +68,7 @@ impl LoginUrl { self } + #[must_use] pub fn request_write_access(mut self, val: bool) -> Self { self.request_write_access = Some(val); self diff --git a/src/types/mask_position.rs b/src/types/mask_position.rs index bf52eccf..f6fd809a 100644 --- a/src/types/mask_position.rs +++ b/src/types/mask_position.rs @@ -45,16 +45,19 @@ impl MaskPosition { self } + #[must_use] pub fn x_shift(mut self, val: f64) -> Self { self.x_shift = val; self } + #[must_use] pub fn y_shift(mut self, val: f64) -> Self { self.y_shift = val; self } + #[must_use] pub fn scale(mut self, val: f64) -> Self { self.scale = val; self diff --git a/src/types/me.rs b/src/types/me.rs index 2d101558..b9cf3fe8 100644 --- a/src/types/me.rs +++ b/src/types/me.rs @@ -26,6 +26,7 @@ pub struct Me { impl Me { /// Returns the username of the bot. + #[must_use] pub fn username(&self) -> &str { self.user .username @@ -34,11 +35,13 @@ impl Me { } /// Returns a username mention of this bot. + #[must_use] pub fn mention(&self) -> String { format!("@{}", self.username()) } /// Returns an URL that links to this bot in the form of `t.me/<...>`. + #[must_use] pub fn tme_url(&self) -> reqwest::Url { format!("https://t.me/{}", self.username()).parse().unwrap() } diff --git a/src/types/message.rs b/src/types/message.rs index 666c206c..54cc09af 100644 --- a/src/types/message.rs +++ b/src/types/message.rs @@ -544,6 +544,7 @@ mod getters { /// [Message]: crate::types::Message /// [telegram docs]: https://core.telegram.org/bots/api#message impl Message { + #[must_use] pub fn from(&self) -> Option<&User> { match &self.kind { Common(MessageCommon { from, .. }) => from.as_ref(), @@ -551,6 +552,7 @@ mod getters { } } + #[must_use] pub fn author_signature(&self) -> Option<&str> { match &self.kind { Common(MessageCommon { @@ -560,6 +562,7 @@ mod getters { } } + #[must_use] pub fn sender_chat(&self) -> Option<&Chat> { match &self.kind { Common(MessageCommon { sender_chat, .. }) => sender_chat.as_ref(), @@ -568,22 +571,27 @@ mod getters { } #[deprecated(since = "0.4.2", note = "use `.chat.id` field instead")] + #[must_use] pub fn chat_id(&self) -> ChatId { self.chat.id } + #[must_use] pub fn forward(&self) -> Option<&Forward> { self.common().and_then(|m| m.forward.as_ref()) } + #[must_use] pub fn forward_date(&self) -> Option> { self.forward().map(|f| f.date) } + #[must_use] pub fn forward_from(&self) -> Option<&ForwardedFrom> { self.forward().map(|f| &f.from) } + #[must_use] pub fn forward_from_user(&self) -> Option<&User> { self.forward_from().and_then(|from| match from { ForwardedFrom::User(user) => Some(user), @@ -591,6 +599,7 @@ mod getters { }) } + #[must_use] pub fn forward_from_chat(&self) -> Option<&Chat> { self.forward_from().and_then(|from| match from { ForwardedFrom::Chat(chat) => Some(chat), @@ -598,6 +607,7 @@ mod getters { }) } + #[must_use] pub fn forward_from_sender_name(&self) -> Option<&str> { self.forward_from().and_then(|from| match from { ForwardedFrom::SenderName(sender_name) => Some(&**sender_name), @@ -605,18 +615,22 @@ mod getters { }) } + #[must_use] pub fn forward_from_message_id(&self) -> Option { self.forward().and_then(|f| f.message_id) } + #[must_use] pub fn forward_signature(&self) -> Option<&str> { self.forward().and_then(|f| f.signature.as_deref()) } + #[must_use] pub fn reply_to_message(&self) -> Option<&Message> { self.common().and_then(|m| m.reply_to_message.as_deref()) } + #[must_use] pub fn edit_date(&self) -> Option<&DateTime> { match &self.kind { Common(MessageCommon { edit_date, .. }) => edit_date.as_ref(), @@ -624,6 +638,7 @@ mod getters { } } + #[must_use] pub fn media_group_id(&self) -> Option<&str> { match &self.kind { Common(MessageCommon { @@ -646,6 +661,7 @@ mod getters { } } + #[must_use] pub fn text(&self) -> Option<&str> { match &self.kind { Common(MessageCommon { @@ -668,6 +684,7 @@ mod getters { /// /// [`parse_entities`]: Message::parse_entities /// [`caption_entities`]: Message::caption_entities + #[must_use] pub fn entities(&self) -> Option<&[MessageEntity]> { match &self.kind { Common(MessageCommon { @@ -690,6 +707,7 @@ mod getters { /// /// [`parse_caption_entities`]: Message::parse_caption_entities /// [`entities`]: Message::entities + #[must_use] pub fn caption_entities(&self) -> Option<&[MessageEntity]> { match &self.kind { Common(MessageCommon { @@ -738,6 +756,7 @@ mod getters { } } + #[must_use] pub fn audio(&self) -> Option<&types::Audio> { match &self.kind { Common(MessageCommon { @@ -748,6 +767,7 @@ mod getters { } } + #[must_use] pub fn document(&self) -> Option<&types::Document> { match &self.kind { Common(MessageCommon { @@ -758,6 +778,7 @@ mod getters { } } + #[must_use] pub fn animation(&self) -> Option<&types::Animation> { match &self.kind { Common(MessageCommon { @@ -768,6 +789,7 @@ mod getters { } } + #[must_use] pub fn game(&self) -> Option<&types::Game> { match &self.kind { Common(MessageCommon { @@ -778,6 +800,7 @@ mod getters { } } + #[must_use] pub fn photo(&self) -> Option<&[PhotoSize]> { match &self.kind { Common(MessageCommon { @@ -788,6 +811,7 @@ mod getters { } } + #[must_use] pub fn sticker(&self) -> Option<&types::Sticker> { match &self.kind { Common(MessageCommon { @@ -798,6 +822,7 @@ mod getters { } } + #[must_use] pub fn video(&self) -> Option<&types::Video> { match &self.kind { Common(MessageCommon { @@ -808,6 +833,7 @@ mod getters { } } + #[must_use] pub fn voice(&self) -> Option<&types::Voice> { match &self.kind { Common(MessageCommon { @@ -818,6 +844,7 @@ mod getters { } } + #[must_use] pub fn video_note(&self) -> Option<&types::VideoNote> { match &self.kind { Common(MessageCommon { @@ -828,6 +855,7 @@ mod getters { } } + #[must_use] pub fn caption(&self) -> Option<&str> { match &self.kind { Common(MessageCommon { media_kind, .. }) => match media_kind { @@ -845,6 +873,7 @@ mod getters { } } + #[must_use] pub fn contact(&self) -> Option<&types::Contact> { match &self.kind { Common(MessageCommon { @@ -855,6 +884,7 @@ mod getters { } } + #[must_use] pub fn location(&self) -> Option<&types::Location> { match &self.kind { Common(MessageCommon { @@ -865,6 +895,7 @@ mod getters { } } + #[must_use] pub fn venue(&self) -> Option<&types::Venue> { match &self.kind { Common(MessageCommon { @@ -875,6 +906,7 @@ mod getters { } } + #[must_use] pub fn poll(&self) -> Option<&types::Poll> { match &self.kind { Common(MessageCommon { @@ -885,6 +917,7 @@ mod getters { } } + #[must_use] pub fn new_chat_members(&self) -> Option<&[User]> { match &self.kind { NewChatMembers(MessageNewChatMembers { new_chat_members }) => { @@ -894,6 +927,7 @@ mod getters { } } + #[must_use] pub fn left_chat_member(&self) -> Option<&User> { match &self.kind { LeftChatMember(MessageLeftChatMember { left_chat_member }) => { @@ -903,6 +937,7 @@ mod getters { } } + #[must_use] pub fn new_chat_title(&self) -> Option<&str> { match &self.kind { NewChatTitle(MessageNewChatTitle { new_chat_title }) => Some(new_chat_title), @@ -910,6 +945,7 @@ mod getters { } } + #[must_use] pub fn new_chat_photo(&self) -> Option<&[PhotoSize]> { match &self.kind { NewChatPhoto(MessageNewChatPhoto { new_chat_photo }) => Some(new_chat_photo), @@ -919,6 +955,7 @@ mod getters { // TODO: OK, `Option` is weird, can we do something with it? // mb smt like `is_delete_chat_photo(&self) -> bool`? + #[must_use] pub fn delete_chat_photo(&self) -> Option { match &self.kind { DeleteChatPhoto(MessageDeleteChatPhoto { delete_chat_photo }) => { @@ -928,6 +965,7 @@ mod getters { } } + #[must_use] pub fn group_chat_created(&self) -> Option { match &self.kind { GroupChatCreated(MessageGroupChatCreated { group_chat_created }) => { @@ -937,6 +975,7 @@ mod getters { } } + #[must_use] pub fn super_group_chat_created(&self) -> Option { match &self.kind { SupergroupChatCreated(MessageSupergroupChatCreated { @@ -946,6 +985,7 @@ mod getters { } } + #[must_use] pub fn channel_chat_created(&self) -> Option { match &self.kind { ChannelChatCreated(MessageChannelChatCreated { @@ -955,6 +995,7 @@ mod getters { } } + #[must_use] pub fn chat_migration(&self) -> Option { match &self.kind { Common(MessageCommon { @@ -965,6 +1006,7 @@ mod getters { } } + #[must_use] pub fn migrate_to_chat_id(&self) -> Option { match &self.kind { Common(MessageCommon { @@ -975,6 +1017,7 @@ mod getters { } } + #[must_use] pub fn migrate_from_chat_id(&self) -> Option { match &self.kind { Common(MessageCommon { @@ -985,6 +1028,7 @@ mod getters { } } + #[must_use] pub fn pinned_message(&self) -> Option<&Message> { match &self.kind { Pinned(MessagePinned { pinned }) => Some(pinned), @@ -992,6 +1036,7 @@ mod getters { } } + #[must_use] pub fn invoice(&self) -> Option<&types::Invoice> { match &self.kind { Invoice(MessageInvoice { invoice }) => Some(invoice), @@ -999,6 +1044,7 @@ mod getters { } } + #[must_use] pub fn successful_payment(&self) -> Option<&types::SuccessfulPayment> { match &self.kind { SuccessfulPayment(MessageSuccessfulPayment { successful_payment }) => { @@ -1008,6 +1054,7 @@ mod getters { } } + #[must_use] pub fn connected_website(&self) -> Option<&str> { match &self.kind { ConnectedWebsite(MessageConnectedWebsite { connected_website }) => { @@ -1017,6 +1064,7 @@ mod getters { } } + #[must_use] pub fn passport_data(&self) -> Option<&types::PassportData> { match &self.kind { PassportData(MessagePassportData { passport_data }) => Some(passport_data), @@ -1024,6 +1072,7 @@ mod getters { } } + #[must_use] pub fn dice(&self) -> Option<&types::Dice> { match &self.kind { Dice(MessageDice { dice }) => Some(dice), @@ -1031,6 +1080,7 @@ mod getters { } } + #[must_use] pub fn proximity_alert_triggered(&self) -> Option<&types::ProximityAlertTriggered> { match &self.kind { ProximityAlertTriggered(MessageProximityAlertTriggered { @@ -1040,6 +1090,7 @@ mod getters { } } + #[must_use] pub fn reply_markup(&self) -> Option<&types::InlineKeyboardMarkup> { match &self.kind { Common(MessageCommon { reply_markup, .. }) => reply_markup.as_ref(), @@ -1047,6 +1098,7 @@ mod getters { } } + #[must_use] pub fn is_automatic_forward(&self) -> bool { match &self.kind { Common(MessageCommon { @@ -1057,6 +1109,7 @@ mod getters { } } + #[must_use] pub fn has_protected_content(&self) -> bool { match &self.kind { Common(MessageCommon { @@ -1085,6 +1138,7 @@ impl Message { /// /// Returns `None` for private chats (i.e.: DMs) and private groups (not /// supergroups). + #[must_use] pub fn url(&self) -> Option { Self::url_of(self.chat.id, self.chat.username(), self.id) } @@ -1103,6 +1157,7 @@ impl Message { /// /// [`url`]: Message::url #[track_caller] + #[must_use] pub fn url_of(chat_id: ChatId, chat_username: Option<&str>, message_id: i32) -> Option { use BareChatId::*; @@ -1146,6 +1201,7 @@ impl Message { /// /// Returns `None` for private chats (i.e.: DMs) and private groups (not /// supergroups). + #[must_use] pub fn comment_url(&self, comment_id: i32) -> Option { Self::comment_url_of(self.chat.id, self.chat.username(), self.id, comment_id) } @@ -1164,6 +1220,7 @@ impl Message { /// supergroups). /// /// [`comment_url`]: Message::comment_url + #[must_use] pub fn comment_url_of( channel_id: ChatId, channel_username: Option<&str>, @@ -1187,6 +1244,7 @@ impl Message { /// /// Returns `None` for private chats (i.e.: DMs) and private groups (not /// supergroups). + #[must_use] pub fn url_in_thread(&self, thread_starter_msg_id: i32) -> Option { Self::url_in_thread_of( self.chat.id, @@ -1214,6 +1272,7 @@ impl Message { /// supergroups). /// /// [`url_in_thread`]: Message::url_in_thread + #[must_use] pub fn url_in_thread_of( chat_id: ChatId, chat_username: Option<&str>, @@ -1235,6 +1294,7 @@ impl Message { /// See also: [`parse_caption_entities`]. /// /// [`parse_caption_entities`]: Message::parse_caption_entities + #[must_use] pub fn parse_entities(&self) -> Option>> { self.text() .zip(self.entities()) @@ -1249,6 +1309,7 @@ impl Message { /// See also: [`parse_entities`]. /// /// [`parse_entities`]: Message::parse_entities + #[must_use] pub fn parse_caption_entities(&self) -> Option>> { self.caption() .zip(self.caption_entities()) diff --git a/src/types/message_entity.rs b/src/types/message_entity.rs index 75e48548..4ac72484 100644 --- a/src/types/message_entity.rs +++ b/src/types/message_entity.rs @@ -43,6 +43,7 @@ pub struct MessageEntityRef<'a> { } impl MessageEntity { + #[must_use] pub const fn new(kind: MessageEntityKind, offset: usize, length: usize) -> Self { Self { kind, @@ -52,6 +53,7 @@ impl MessageEntity { } /// Create a message entity representing a bold text. + #[must_use] pub const fn bold(offset: usize, length: usize) -> Self { Self { kind: MessageEntityKind::Bold, @@ -61,6 +63,7 @@ impl MessageEntity { } /// Create a message entity representing an italic text. + #[must_use] pub const fn italic(offset: usize, length: usize) -> Self { Self { kind: MessageEntityKind::Italic, @@ -70,6 +73,7 @@ impl MessageEntity { } /// Create a message entity representing an underline text. + #[must_use] pub const fn underline(offset: usize, length: usize) -> Self { Self { kind: MessageEntityKind::Underline, @@ -79,6 +83,7 @@ impl MessageEntity { } /// Create a message entity representing a strikethrough text. + #[must_use] pub const fn strikethrough(offset: usize, length: usize) -> Self { Self { kind: MessageEntityKind::Strikethrough, @@ -88,6 +93,7 @@ impl MessageEntity { } /// Create a message entity representing a spoiler text. + #[must_use] pub const fn spoiler(offset: usize, length: usize) -> Self { Self { kind: MessageEntityKind::Spoiler, @@ -97,6 +103,7 @@ impl MessageEntity { } /// Create a message entity representing a monowidth text. + #[must_use] pub const fn code(offset: usize, length: usize) -> Self { Self { kind: MessageEntityKind::Code, @@ -106,6 +113,7 @@ impl MessageEntity { } /// Create a message entity representing a monowidth block. + #[must_use] pub const fn pre(language: Option, offset: usize, length: usize) -> Self { Self { kind: MessageEntityKind::Pre { language }, @@ -115,6 +123,7 @@ impl MessageEntity { } /// Create a message entity representing a clickable text URL. + #[must_use] pub const fn text_link(url: reqwest::Url, offset: usize, length: usize) -> Self { Self { kind: MessageEntityKind::TextLink { url }, @@ -129,6 +138,7 @@ impl MessageEntity { /// /// If you don't have a complete [`User`] value, please use /// [`MessageEntity::text_mention_id`] instead. + #[must_use] pub fn text_mention(user: User, offset: usize, length: usize) -> Self { Self { kind: MessageEntityKind::TextMention { user }, @@ -139,6 +149,7 @@ impl MessageEntity { /// Create a message entity representing a text link in the form of /// `tg://user/?id=...` that mentions user with `user_id`. + #[must_use] pub fn text_mention_id(user_id: UserId, offset: usize, length: usize) -> Self { Self { kind: MessageEntityKind::TextLink { url: user_id.url() }, @@ -147,16 +158,19 @@ impl MessageEntity { } } + #[must_use] pub fn kind(mut self, val: MessageEntityKind) -> Self { self.kind = val; self } + #[must_use] pub const fn offset(mut self, val: usize) -> Self { self.offset = val; self } + #[must_use] pub const fn length(mut self, val: usize) -> Self { self.length = val; self @@ -165,11 +179,13 @@ impl MessageEntity { impl<'a> MessageEntityRef<'a> { /// Returns kind of this entity. + #[must_use] pub fn kind(&self) -> &'a MessageEntityKind { self.kind } /// Returns the text that this entity is related to. + #[must_use] pub fn text(&self) -> &'a str { &self.message[self.range.clone()] } @@ -178,34 +194,40 @@ impl<'a> MessageEntityRef<'a> { /// /// The range is in bytes for UTF-8 encoding i.e. you can use it with common /// Rust strings. + #[must_use] pub fn range(&self) -> Range { self.range.clone() } /// Returns the offset (in bytes, for UTF-8) to the start of this entity in /// the original message. + #[must_use] pub fn start(&self) -> usize { self.range.start } /// Returns the offset (in bytes, for UTF-8) to the end of this entity in /// the original message. + #[must_use] pub fn end(&self) -> usize { self.range.end } /// Returns the length of this entity in bytes for UTF-8 encoding. #[allow(clippy::len_without_is_empty)] + #[must_use] pub fn len(&self) -> usize { self.range.len() } /// Returns the full text of the original message. + #[must_use] pub fn message_text(&self) -> &'a str { self.message } /// Parses telegram [`MessageEntity`]s converting offsets to UTF-8. + #[must_use] pub fn parse(text: &'a str, entities: &'a [MessageEntity]) -> Vec { // This creates entities with **wrong** offsets (UTF-16) that we later patch. let mut entities: Vec<_> = entities diff --git a/src/types/passport_element_error.rs b/src/types/passport_element_error.rs index dd594ba7..3021bc69 100644 --- a/src/types/passport_element_error.rs +++ b/src/types/passport_element_error.rs @@ -32,6 +32,7 @@ impl PassportElementError { self } + #[must_use] pub fn kind(mut self, val: PassportElementErrorKind) -> Self { self.kind = val; self @@ -104,6 +105,7 @@ impl PassportElementErrorDataField { } } + #[must_use] pub fn r#type(mut self, val: PassportElementErrorDataFieldType) -> Self { self.r#type = val; self @@ -153,6 +155,7 @@ impl PassportElementErrorFrontSide { } } + #[must_use] pub fn r#type(mut self, val: PassportElementErrorFrontSideType) -> Self { self.r#type = val; self @@ -194,6 +197,7 @@ impl PassportElementErrorReverseSide { } } + #[must_use] pub fn r#type(mut self, val: PassportElementErrorReverseSideType) -> Self { self.r#type = val; self @@ -233,6 +237,7 @@ impl PassportElementErrorSelfie { } } + #[must_use] pub fn r#type(mut self, val: PassportElementErrorSelfieType) -> Self { self.r#type = val; self @@ -273,6 +278,7 @@ impl PassportElementErrorFile { } } + #[must_use] pub fn r#type(mut self, val: PassportElementErrorFileType) -> Self { self.r#type = val; self @@ -313,6 +319,7 @@ impl PassportElementErrorFiles { } } + #[must_use] pub fn r#type(mut self, val: PassportElementErrorFilesType) -> Self { self.r#type = val; self @@ -354,6 +361,7 @@ impl PassportElementErrorTranslationFile { } } + #[must_use] pub fn r#type(mut self, val: PassportElementErrorTranslationFileType) -> Self { self.r#type = val; self @@ -394,6 +402,7 @@ impl PassportElementErrorTranslationFiles { } } + #[must_use] pub fn r#type(mut self, val: PassportElementErrorTranslationFilesType) -> Self { self.r#type = val; self @@ -434,6 +443,7 @@ impl PassportElementErrorUnspecified { } } + #[must_use] pub fn r#type(mut self, val: PassportElementErrorUnspecifiedType) -> Self { self.r#type = val; self diff --git a/src/types/reply_keyboard_markup.rs b/src/types/reply_keyboard_markup.rs index 05d87ff3..8a80cb7b 100644 --- a/src/types/reply_keyboard_markup.rs +++ b/src/types/reply_keyboard_markup.rs @@ -75,6 +75,7 @@ impl KeyboardMarkup { self } + #[must_use] pub fn append_to_row(mut self, index: usize, button: KeyboardButton) -> Self { match self.keyboard.get_mut(index) { Some(buttons) => buttons.push(button), diff --git a/src/types/reply_keyboard_remove.rs b/src/types/reply_keyboard_remove.rs index 7e8490c7..4f2e85e1 100644 --- a/src/types/reply_keyboard_remove.rs +++ b/src/types/reply_keyboard_remove.rs @@ -38,6 +38,7 @@ pub struct KeyboardRemove { } impl KeyboardRemove { + #[must_use] pub const fn new() -> Self { Self { remove_keyboard: True, @@ -45,6 +46,7 @@ impl KeyboardRemove { } } + #[must_use] pub const fn selective(mut self, val: bool) -> Self { self.selective = Some(val); self diff --git a/src/types/reply_markup.rs b/src/types/reply_markup.rs index 7f9c07a0..d2e179bf 100644 --- a/src/types/reply_markup.rs +++ b/src/types/reply_markup.rs @@ -50,6 +50,7 @@ impl ReplyMarkup { /// `ReplyMarkup::KeyboardRemove(ReplyKeyboardRemove::new()))`. /// /// [`KeyboardRemove`]: ReplyMarkup::KeyboardRemove + #[must_use] pub fn kb_remove() -> Self { Self::KeyboardRemove(KeyboardRemove::new()) } @@ -59,6 +60,7 @@ impl ReplyMarkup { /// This is a shortcut to `ReplyMarkup::ForceReply(ForceReply::new())`. /// /// [`ForceReply`]: ReplyMarkup::KeyboardRemove + #[must_use] pub fn force_reply() -> Self { Self::ForceReply(ForceReply::new()) } diff --git a/src/types/sticker.rs b/src/types/sticker.rs index e48afb4d..3d96af32 100644 --- a/src/types/sticker.rs +++ b/src/types/sticker.rs @@ -84,6 +84,7 @@ impl Deref for Sticker { impl StickerKind { /// Returns `true` is this is a "normal" raster sticker. + #[must_use] pub fn is_webp(&self) -> bool { matches!(self, Self::Webp) } @@ -91,6 +92,7 @@ impl StickerKind { /// Returns `true` is this is an [animated] sticker. /// /// [animated]: https://telegram.org/blog/animated-stickers + #[must_use] pub fn is_animated(&self) -> bool { matches!(self, Self::Animated) } @@ -98,6 +100,7 @@ impl StickerKind { /// Returns `true` is this is a [video] sticker. /// /// [video]: https://telegram.org/blog/video-stickers-better-reactions + #[must_use] pub fn is_video(&self) -> bool { matches!(self, Self::Video) } diff --git a/src/types/update.rs b/src/types/update.rs index 81f35224..05b55133 100644 --- a/src/types/update.rs +++ b/src/types/update.rs @@ -29,6 +29,7 @@ pub struct Update { } impl Update { + #[must_use] pub fn user(&self) -> Option<&User> { match &self.kind { UpdateKind::Message(m) => m.from(), @@ -43,6 +44,7 @@ impl Update { } } + #[must_use] pub fn chat(&self) -> Option<&Chat> { match &self.kind { UpdateKind::Message(m) => Some(&m.chat), diff --git a/src/types/user.rs b/src/types/user.rs index 7d155464..4d6a2da4 100644 --- a/src/types/user.rs +++ b/src/types/user.rs @@ -40,6 +40,7 @@ pub struct User { impl User { /// Returns full name of this user, ie first and last names joined with a /// space. + #[must_use] pub fn full_name(&self) -> String { match &self.last_name { Some(last_name) => (format!("{0} {1}", self.first_name, last_name)), @@ -49,18 +50,21 @@ impl User { /// Returns a username mention of this user. Returns `None` if /// `self.username.is_none()`. + #[must_use] pub fn mention(&self) -> Option { Some(format!("@{}", self.username.as_ref()?)) } /// Returns an URL that links to this user in the form of /// `tg://user/?id=<...>`. + #[must_use] pub fn url(&self) -> reqwest::Url { self.id.url() } /// Returns an URL that links to this user in the form of `t.me/<...>`. /// Returns `None` if `self.username.is_none()`. + #[must_use] pub fn tme_url(&self) -> Option { Some( format!("https://t.me/{}", self.username.as_ref()?) @@ -71,12 +75,14 @@ impl User { /// Returns an URL that links to this user in the form of `t.me/<...>` or /// `tg://user/?id=<...>`, preferring `t.me` one when possible. + #[must_use] pub fn preferably_tme_url(&self) -> reqwest::Url { self.tme_url().unwrap_or_else(|| self.url()) } /// Returns `true` if this is the special user used by telegram bot API to /// denote an anonymous user that sends messages on behalf of a group. + #[must_use] pub fn is_anonymous(&self) -> bool { // Sanity check debug_assert!( @@ -92,6 +98,7 @@ impl User { /// Returns `true` if this is the special user used by telegram bot API to /// denote an anonymous user that sends messages on behalf of a channel. + #[must_use] pub fn is_channel(&self) -> bool { // Sanity check debug_assert!( @@ -110,6 +117,7 @@ impl User { /// It is sometimes also used as a fallback, for example when a channel post /// is automatically forwarded to a group, bots in a group will get a /// message where `from` is the Telegram user. + #[must_use] pub fn is_telegram(&self) -> bool { // Sanity check debug_assert!( diff --git a/src/types/user_id.rs b/src/types/user_id.rs index fe31e573..a767234c 100644 --- a/src/types/user_id.rs +++ b/src/types/user_id.rs @@ -11,6 +11,7 @@ pub struct UserId(pub u64); impl UserId { /// Returns an URL that links to the user with this id in the form of /// `tg://user/?id=<...>`. + #[must_use] pub fn url(self) -> reqwest::Url { reqwest::Url::parse(&format!("tg://user/?id={}", self)).unwrap() } @@ -18,6 +19,7 @@ impl UserId { /// Returns `true` if this is the id of the special user used by telegram /// bot API to denote an anonymous user that sends messages on behalf of /// a group. + #[must_use] pub fn is_anonymous(self) -> bool { // https://github.com/tdlib/td/blob/4791fb6a2af0257f6cad8396e10424a79ee5f768/td/telegram/ContactsManager.cpp#L4941-L4943 const ANON_ID: UserId = UserId(1087968824); @@ -28,6 +30,7 @@ impl UserId { /// Returns `true` if this is the id of the special user used by telegram /// bot API to denote an anonymous user that sends messages on behalf of /// a channel. + #[must_use] pub fn is_channel(self) -> bool { // https://github.com/tdlib/td/blob/4791fb6a2af0257f6cad8396e10424a79ee5f768/td/telegram/ContactsManager.cpp#L4945-L4947 const ANON_CHANNEL_ID: UserId = UserId(136817688); @@ -41,6 +44,7 @@ impl UserId { /// It is sometimes also used as a fallback, for example when a channel post /// is automatically forwarded to a group, bots in a group will get a /// message where `from` is the Telegram user. + #[must_use] pub fn is_telegram(self) -> bool { const TELEGRAM_USER_ID: UserId = UserId(777000); From e26c839d1a9792b45d11af2a73277b9ba348a1ff Mon Sep 17 00:00:00 2001 From: Waffle Maybe Date: Mon, 15 Aug 2022 20:08:20 +0400 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91b7e20b..2f2e9445 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [pr241]: https://github.com/teloxide/teloxide-core/pull/241 +### Changed + +- More functions are now marked with `#[must_use]` ([#242][PR242]) + +[pr242]: https://github.com/teloxide/teloxide-core/pull/242 + ## 0.7.0 - 2022-07-19 ### Added From d30d4f36cd76cc179156275ade1f21cbc960b892 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 15 Aug 2022 20:10:16 +0400 Subject: [PATCH 3/3] Remove useless parentheses --- src/types/user.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/user.rs b/src/types/user.rs index 4d6a2da4..07c14052 100644 --- a/src/types/user.rs +++ b/src/types/user.rs @@ -43,7 +43,7 @@ impl User { #[must_use] pub fn full_name(&self) -> String { match &self.last_name { - Some(last_name) => (format!("{0} {1}", self.first_name, last_name)), + Some(last_name) => format!("{0} {1}", self.first_name, last_name), None => self.first_name.clone(), } }