Merge pull request #769 from teloxide/const-must-use

More `const` and `#[must_use]` functions
This commit is contained in:
Sima Kinsart 2022-12-09 22:31:19 +06:00 committed by GitHub
commit a435266e89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 20 additions and 4 deletions

View file

@ -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**] - `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 ## 0.11.3 - 2022-11-28
### Fixed ### Fixed

View file

@ -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 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 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 ### Added

View file

@ -130,7 +130,7 @@ impl Bot {
/// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html /// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html
/// [issue 223]: https://github.com/teloxide/teloxide/issues/223 /// [issue 223]: https://github.com/teloxide/teloxide/issues/223
pub fn from_env_with_client(client: Client) -> Self { 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. /// Sets a custom API URL.

View file

@ -43,7 +43,7 @@ pub fn client_from_env() -> reqwest::Client {
let builder = default_reqwest_settings(); let builder = default_reqwest_settings();
match std::env::var(TELOXIDE_PROXY).ok() { 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, None => builder,
} }
.build() .build()

View file

@ -35,10 +35,12 @@ pub enum MaskPoint {
} }
impl MaskPosition { impl MaskPosition {
#[must_use]
pub const fn new(point: MaskPoint, x_shift: f64, y_shift: f64, scale: f64) -> Self { pub const fn new(point: MaskPoint, x_shift: f64, y_shift: f64, scale: f64) -> Self {
Self { point, x_shift, y_shift, scale } Self { point, x_shift, y_shift, scale }
} }
#[must_use]
pub const fn point(mut self, val: MaskPoint) -> Self { pub const fn point(mut self, val: MaskPoint) -> Self {
self.point = val; self.point = val;
self self

View file

@ -200,6 +200,7 @@ impl StickerKind {
} }
/// Getter for [`StickerKind::Regular::premium_animation`]. /// Getter for [`StickerKind::Regular::premium_animation`].
#[must_use]
pub fn premium_animation(&self) -> Option<&FileMeta> { pub fn premium_animation(&self) -> Option<&FileMeta> {
if let Self::Regular { premium_animation } = self { if let Self::Regular { premium_animation } = self {
premium_animation.as_ref() premium_animation.as_ref()
@ -209,6 +210,7 @@ impl StickerKind {
} }
/// Getter for [`StickerKind::Mask::mask_position`]. /// Getter for [`StickerKind::Mask::mask_position`].
#[must_use]
pub fn mask_position(&self) -> Option<MaskPosition> { pub fn mask_position(&self) -> Option<MaskPosition> {
if let Self::Mask { mask_position } = self { if let Self::Mask { mask_position } = self {
Some(*mask_position) Some(*mask_position)
@ -218,6 +220,7 @@ impl StickerKind {
} }
/// Getter for [`StickerKind::CustomEmoji::custom_emoji_id`]. /// Getter for [`StickerKind::CustomEmoji::custom_emoji_id`].
#[must_use]
pub fn custom_emoji_id(&self) -> Option<&str> { pub fn custom_emoji_id(&self) -> Option<&str> {
if let Self::CustomEmoji { custom_emoji_id } = self { if let Self::CustomEmoji { custom_emoji_id } = self {
Some(custom_emoji_id) Some(custom_emoji_id)

View file

@ -86,6 +86,7 @@ where
/// ///
/// [`shutdown`]: ShutdownToken::shutdown /// [`shutdown`]: ShutdownToken::shutdown
#[cfg(feature = "ctrlc_handler")] #[cfg(feature = "ctrlc_handler")]
#[must_use]
pub fn enable_ctrlc_handler(self) -> Self { pub fn enable_ctrlc_handler(self) -> Self {
Self { ctrlc_handler: true, ..self } Self { ctrlc_handler: true, ..self }
} }
@ -100,6 +101,7 @@ where
/// Specifies the distribution function that decides how updates are grouped /// Specifies the distribution function that decides how updates are grouped
/// before execution. /// before execution.
#[must_use]
pub fn distribution_function<K>( pub fn distribution_function<K>(
self, self,
f: fn(&Update) -> Option<K>, f: fn(&Update) -> Option<K>,

View file

@ -133,7 +133,7 @@ pub trait AsUpdateStream<'a> {
} }
#[inline(always)] #[inline(always)]
pub(crate) fn assert_update_listener<L>(listener: L) -> L pub(crate) const fn assert_update_listener<L>(listener: L) -> L
where where
L: UpdateListener, L: UpdateListener,
{ {

View file

@ -298,7 +298,7 @@ pub struct CommandDescription<'a> {
impl<'a> CommandDescriptions<'a> { impl<'a> CommandDescriptions<'a> {
/// Creates new [`CommandDescriptions`] from a list of command descriptions. /// Creates new [`CommandDescriptions`] from a list of command descriptions.
#[must_use] #[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 } Self { global_description: None, descriptions, bot_username: None }
} }