Merge pull request #1005 from Henriquelay/master

Implement `GetChatId` for `teloxide-core::types::*`
This commit is contained in:
Waffle Maybe 2024-03-16 22:10:28 +00:00 committed by GitHub
commit 60d092882f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 2 deletions

View file

@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `filter_video_chat_ended`
- `filter_video_chat_participants_invited`
- `filter_web_app_data`
- Implement `GetChatId` for `teloxide_core::types::{Chat, ChatJoinRequest, ChatMemberUpdated}`.
### Fixed

View file

@ -1,6 +1,8 @@
use crate::types::{CallbackQuery, ChatId, Message, Update};
use crate::types::{
CallbackQuery, Chat, ChatId, ChatJoinRequest, ChatMemberUpdated, Message, Update,
};
/// Something that may has a chat ID.
/// Something that may have a chat ID.
pub trait GetChatId {
#[must_use]
fn chat_id(&self) -> Option<ChatId>;
@ -23,3 +25,21 @@ impl GetChatId for Update {
self.chat().map(|chat| chat.id)
}
}
impl GetChatId for Chat {
fn chat_id(&self) -> Option<ChatId> {
Some(self.id)
}
}
impl GetChatId for ChatMemberUpdated {
fn chat_id(&self) -> Option<ChatId> {
Some(self.chat.id)
}
}
impl GetChatId for ChatJoinRequest {
fn chat_id(&self) -> Option<ChatId> {
Some(self.chat.id)
}
}