mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 06:25:10 +01:00
Use serde(flatten) for BusinessConnectionId
This commit is contained in:
parent
951c8f1438
commit
17b3807d3f
4 changed files with 6 additions and 22 deletions
|
@ -2,33 +2,15 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
/// A unique business connection identifier.
|
||||
#[derive(Default, Clone, Debug, derive_more::Display, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(from = "BusinessConnectionIdRaw", into = "BusinessConnectionIdRaw")]
|
||||
pub struct BusinessConnectionId(pub String);
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct BusinessConnectionIdRaw {
|
||||
business_connection_id: String,
|
||||
}
|
||||
|
||||
impl From<BusinessConnectionIdRaw> for BusinessConnectionId {
|
||||
fn from(BusinessConnectionIdRaw { business_connection_id }: BusinessConnectionIdRaw) -> Self {
|
||||
BusinessConnectionId(business_connection_id)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BusinessConnectionId> for BusinessConnectionIdRaw {
|
||||
fn from(BusinessConnectionId(business_connection_id): BusinessConnectionId) -> Self {
|
||||
BusinessConnectionIdRaw { business_connection_id }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::types::BusinessConnectionId;
|
||||
|
||||
#[test]
|
||||
fn business_connection_id_deser() {
|
||||
let json = r#"{"business_connection_id": "abcd1234"}"#;
|
||||
let json = r#""abcd1234""#;
|
||||
let bcid: BusinessConnectionId = serde_json::from_str(json).unwrap();
|
||||
assert_eq!(bcid, BusinessConnectionId(String::from("abcd1234")));
|
||||
}
|
||||
|
@ -37,6 +19,6 @@ mod tests {
|
|||
fn business_connection_id_ser() {
|
||||
let bcid: BusinessConnectionId = BusinessConnectionId(String::from("abcd1234"));
|
||||
let json = serde_json::to_string(&bcid).unwrap();
|
||||
assert_eq!(json, r#"{"business_connection_id":"abcd1234"}"#);
|
||||
assert_eq!(json, r#""abcd1234""#);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ use crate::types::{BusinessConnectionId, Chat, MessageId};
|
|||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct BusinessMessagesDeleted {
|
||||
/// Unique identifier of the business connection.
|
||||
#[serde(flatten)]
|
||||
pub business_connection_id: BusinessConnectionId,
|
||||
|
||||
/// Information about a chat in the business account. The bot may not have
|
||||
|
|
|
@ -169,6 +169,7 @@ pub struct MessageCommon {
|
|||
/// received. If non-empty, the message belongs to a chat of the
|
||||
/// corresponding business account that is independent from any potential
|
||||
/// bot chat which might share the same identifier.
|
||||
#[serde(flatten)]
|
||||
pub business_connection_id: Option<BusinessConnectionId>,
|
||||
}
|
||||
|
||||
|
|
|
@ -1007,7 +1007,7 @@ mod test {
|
|||
"#;
|
||||
let chat = Chat {
|
||||
id: ChatId(-1002199793788),
|
||||
kind: ChatKind::Public(ChatPublic {
|
||||
kind: ChatKind::Public(Box::new(ChatPublic {
|
||||
title: Some("тест".to_owned()),
|
||||
kind: PublicChatKind::Supergroup(PublicChatSupergroup {
|
||||
username: None,
|
||||
|
@ -1027,7 +1027,7 @@ mod test {
|
|||
description: None,
|
||||
invite_link: None,
|
||||
has_protected_content: None,
|
||||
}),
|
||||
})),
|
||||
photo: None,
|
||||
available_reactions: None,
|
||||
pinned_message: None,
|
||||
|
|
Loading…
Reference in a new issue