diff --git a/CHANGELOG.md b/CHANGELOG.md index fe0ca592..f5748e0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `rocksdb-storage` feature and associated items (See [PR #761](https://github.com/teloxide/teloxide/pull/761) for reasoning) [**BC**] +## Changed + +- `CommandDescriptions::new` is made `const` +- The following functions were made `#[must_use]`: + - `DispatcherBuilder::{enable_ctrlc_handler, distribution_function}` + ## 0.11.3 - 2022-11-28 ### Fixed diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index c9e9d582..0e5c1487 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The methods `ChatMember::{can_pin_messages, can_invite_users, can_change_info}` now take into account the permissions of `Restricted` chat member kind ([#764][pr764]) - The method `ChatMemberKind::is_present` now takes into account the value of `Restricted::is_member` field ([#764][pr764]) +- The following functions were made `#[must_use]`: + - `MaskPoint::{new, point}` + - `StickerKind::{premium_animation, mask_position, custom_emoji_id}` ### Added diff --git a/crates/teloxide-core/src/bot.rs b/crates/teloxide-core/src/bot.rs index ef0801f8..b8f9d67e 100644 --- a/crates/teloxide-core/src/bot.rs +++ b/crates/teloxide-core/src/bot.rs @@ -130,7 +130,7 @@ impl Bot { /// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html /// [issue 223]: https://github.com/teloxide/teloxide/issues/223 pub fn from_env_with_client(client: Client) -> Self { - Self::with_client(&get_env(TELOXIDE_TOKEN), client) + Self::with_client(get_env(TELOXIDE_TOKEN), client) } /// Sets a custom API URL. diff --git a/crates/teloxide-core/src/net.rs b/crates/teloxide-core/src/net.rs index d7f96a76..5bd12342 100644 --- a/crates/teloxide-core/src/net.rs +++ b/crates/teloxide-core/src/net.rs @@ -43,7 +43,7 @@ pub fn client_from_env() -> reqwest::Client { let builder = default_reqwest_settings(); match std::env::var(TELOXIDE_PROXY).ok() { - Some(proxy) => builder.proxy(Proxy::all(&proxy).expect("reqwest::Proxy creation failed")), + Some(proxy) => builder.proxy(Proxy::all(proxy).expect("reqwest::Proxy creation failed")), None => builder, } .build() diff --git a/crates/teloxide-core/src/types/mask_position.rs b/crates/teloxide-core/src/types/mask_position.rs index 147654e1..fd736dcf 100644 --- a/crates/teloxide-core/src/types/mask_position.rs +++ b/crates/teloxide-core/src/types/mask_position.rs @@ -35,10 +35,12 @@ pub enum MaskPoint { } impl MaskPosition { + #[must_use] pub const fn new(point: MaskPoint, x_shift: f64, y_shift: f64, scale: f64) -> Self { Self { point, x_shift, y_shift, scale } } + #[must_use] pub const fn point(mut self, val: MaskPoint) -> Self { self.point = val; self diff --git a/crates/teloxide-core/src/types/sticker.rs b/crates/teloxide-core/src/types/sticker.rs index 0424b7ae..6f41fccc 100644 --- a/crates/teloxide-core/src/types/sticker.rs +++ b/crates/teloxide-core/src/types/sticker.rs @@ -200,6 +200,7 @@ impl StickerKind { } /// Getter for [`StickerKind::Regular::premium_animation`]. + #[must_use] pub fn premium_animation(&self) -> Option<&FileMeta> { if let Self::Regular { premium_animation } = self { premium_animation.as_ref() @@ -209,6 +210,7 @@ impl StickerKind { } /// Getter for [`StickerKind::Mask::mask_position`]. + #[must_use] pub fn mask_position(&self) -> Option { if let Self::Mask { mask_position } = self { Some(*mask_position) @@ -218,6 +220,7 @@ impl StickerKind { } /// Getter for [`StickerKind::CustomEmoji::custom_emoji_id`]. + #[must_use] pub fn custom_emoji_id(&self) -> Option<&str> { if let Self::CustomEmoji { custom_emoji_id } = self { Some(custom_emoji_id) diff --git a/crates/teloxide/src/dispatching/dispatcher.rs b/crates/teloxide/src/dispatching/dispatcher.rs index 874e9892..954a6ecd 100644 --- a/crates/teloxide/src/dispatching/dispatcher.rs +++ b/crates/teloxide/src/dispatching/dispatcher.rs @@ -86,6 +86,7 @@ where /// /// [`shutdown`]: ShutdownToken::shutdown #[cfg(feature = "ctrlc_handler")] + #[must_use] pub fn enable_ctrlc_handler(self) -> Self { Self { ctrlc_handler: true, ..self } } @@ -100,6 +101,7 @@ where /// Specifies the distribution function that decides how updates are grouped /// before execution. + #[must_use] pub fn distribution_function( self, f: fn(&Update) -> Option, diff --git a/crates/teloxide/src/dispatching/update_listeners.rs b/crates/teloxide/src/dispatching/update_listeners.rs index 4103e398..5594d949 100644 --- a/crates/teloxide/src/dispatching/update_listeners.rs +++ b/crates/teloxide/src/dispatching/update_listeners.rs @@ -133,7 +133,7 @@ pub trait AsUpdateStream<'a> { } #[inline(always)] -pub(crate) fn assert_update_listener(listener: L) -> L +pub(crate) const fn assert_update_listener(listener: L) -> L where L: UpdateListener, { diff --git a/crates/teloxide/src/utils/command.rs b/crates/teloxide/src/utils/command.rs index 8f96998e..95ef0000 100644 --- a/crates/teloxide/src/utils/command.rs +++ b/crates/teloxide/src/utils/command.rs @@ -298,7 +298,7 @@ pub struct CommandDescription<'a> { impl<'a> CommandDescriptions<'a> { /// Creates new [`CommandDescriptions`] from a list of command descriptions. #[must_use] - pub fn new(descriptions: &'a [CommandDescription<'a>]) -> Self { + pub const fn new(descriptions: &'a [CommandDescription<'a>]) -> Self { Self { global_description: None, descriptions, bot_username: None } }