Impl From<UserId> for ChatId and Recipient

This commit is contained in:
Maybe Waffle 2022-03-24 20:47:30 +04:00
parent 036c46caaa
commit 4fbec56674
2 changed files with 13 additions and 1 deletions

View file

@ -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(_))

View file

@ -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::*;