From ae0451f7d72e78fdeb317db397fb602a29eda17a Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Sat, 29 Jul 2023 14:09:09 +0400 Subject: [PATCH] Add `UserId::{MIN, MAX}` constants --- crates/teloxide-core/CHANGELOG.md | 1 + crates/teloxide-core/src/types/chat_id.rs | 4 ++-- crates/teloxide-core/src/types/user_id.rs | 8 +++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index 48216103..6cfbee78 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `ThreadId` newtype over `MessageId`, used for identifying reply threads ([#887][pr887]) - `ChatId::as_user` ([#905][pr905]) - Implement `PartialEq for UserId` and `PartialEq for ChatId` ([#905][pr905]) +- `ChatId::{MIN, MAX}` ([#905][pr905]) [pr851]: https://github.com/teloxide/teloxide/pull/851 [pr887]: https://github.com/teloxide/teloxide/pull/887 diff --git a/crates/teloxide-core/src/types/chat_id.rs b/crates/teloxide-core/src/types/chat_id.rs index f9cdb32c..336d3f91 100644 --- a/crates/teloxide-core/src/types/chat_id.rs +++ b/crates/teloxide-core/src/types/chat_id.rs @@ -107,8 +107,8 @@ const MIN_MARKED_CHANNEL_ID: i64 = -1997852516352; const MAX_MARKED_CHANNEL_ID: i64 = -1000000000000; const MIN_MARKED_CHAT_ID: i64 = MAX_MARKED_CHANNEL_ID + 1; const MAX_MARKED_CHAT_ID: i64 = MIN_USER_ID - 1; -const MIN_USER_ID: i64 = 0; -const MAX_USER_ID: i64 = (1 << 40) - 1; +pub(crate) const MIN_USER_ID: i64 = 0; +pub(crate) const MAX_USER_ID: i64 = (1 << 40) - 1; #[cfg(test)] mod tests { diff --git a/crates/teloxide-core/src/types/user_id.rs b/crates/teloxide-core/src/types/user_id.rs index 625a1691..4c102a36 100644 --- a/crates/teloxide-core/src/types/user_id.rs +++ b/crates/teloxide-core/src/types/user_id.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::types::ChatId; +use crate::types::{ChatId, MAX_USER_ID, MIN_USER_ID}; /// Identifier of a user. #[derive(Clone, Copy)] @@ -52,6 +52,12 @@ impl UserId { self == TELEGRAM_USER_ID } + + /// The smallest user id that could possibly be returned by Telegram. + pub const MIN: Self = Self(MIN_USER_ID as u64); + + /// The largest user id that could possibly be returned by Telegram. + pub const MAX: Self = Self(MAX_USER_ID as u64); } impl PartialEq for UserId {