mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-10 20:12:25 +01:00
Impl From<UserId>
for ChatId
and Recipient
This commit is contained in:
parent
036c46caaa
commit
4fbec56674
2 changed files with 13 additions and 1 deletions
|
@ -12,6 +12,12 @@ use crate::types::UserId;
|
|||
#[serde(transparent)]
|
||||
pub struct ChatId(pub i64);
|
||||
|
||||
impl From<UserId> for ChatId {
|
||||
fn from(UserId(id): UserId) -> Self {
|
||||
Self(id as _)
|
||||
}
|
||||
}
|
||||
|
||||
impl ChatId {
|
||||
pub(crate) fn is_channel(self) -> bool {
|
||||
matches!(self.unmark(), UnmarkedChatId::Channel(_))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use derive_more::{Display, From};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::ChatId;
|
||||
use crate::types::{ChatId, UserId};
|
||||
|
||||
/// A unique identifier for the target chat or username of the target channel
|
||||
/// (in the format `@channelusername`).
|
||||
|
@ -29,6 +29,12 @@ impl Recipient {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<UserId> for Recipient {
|
||||
fn from(id: UserId) -> Self {
|
||||
Self::Id(id.into())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Reference in a new issue