Fix deserialization of some unit structures

This commit is contained in:
Maybe Waffle 2023-04-24 19:31:11 +04:00
parent b7c1cd9494
commit e986c89a61
8 changed files with 33 additions and 6 deletions

View file

@ -43,9 +43,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Voice::duration`
- `RequestError::MigrateToChatId` single fields type to `ChatId` ([#859][pr859])
- `RequestError::RetryAfter` single fields type to `Seconds` ([#859][pr859])
- `CallbackGame`, `ForumTopicClosed`, `ForumTopicReopened`, `GeneralForumTopicHidden`, `GeneralForumTopicUnhidden` and `WriteAccessAllowed` structures
are now defined as named (`struct S {}`) instead of unit (`struct S;`) in order to fix their deserialization ([#876][pr876])
[pr852]: https://github.com/teloxide/teloxide/pull/853
[pr859]: https://github.com/teloxide/teloxide/pull/859
[pr876]: https://github.com/teloxide/teloxide/pull/876
### Deprecated

View file

@ -9,4 +9,4 @@ use serde::{Deserialize, Serialize};
///
/// [@Botfather]: https://t.me/botfather
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct CallbackGame;
pub struct CallbackGame {}

View file

@ -6,4 +6,4 @@ use serde::{Deserialize, Serialize};
/// [The official docs](https://core.telegram.org/bots/api#forumtopicclosed).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct ForumTopicClosed;
pub struct ForumTopicClosed {}

View file

@ -6,4 +6,4 @@ use serde::{Deserialize, Serialize};
/// [The official docs](https://core.telegram.org/bots/api#forumtopicreopened).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct ForumTopicReopened;
pub struct ForumTopicReopened {}

View file

@ -6,4 +6,4 @@ use serde::{Deserialize, Serialize};
/// [The official docs](https://core.telegram.org/bots/api#generalforumtopichidden).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct GeneralForumTopicHidden;
pub struct GeneralForumTopicHidden {}

View file

@ -6,4 +6,4 @@ use serde::{Deserialize, Serialize};
/// [The official docs](https://core.telegram.org/bots/api#generalforumtopicunhidden).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct GeneralForumTopicUnhidden;
pub struct GeneralForumTopicUnhidden {}

View file

@ -1933,4 +1933,28 @@ mod tests {
let msg: Message = serde_json::from_str(json).unwrap();
assert_matches!(msg.kind, MessageKind::Empty {})
}
#[test]
fn issue_874() {
let json = r#"{
"chat": {
"id": -1001840751935,
"is_forum": true,
"title": "AI",
"type": "supergroup"
},
"date": 1682191229,
"forum_topic_closed": {},
"from": {
"first_name": "Владислав",
"id": 112455916,
"is_bot": false,
"language_code": "en",
"username": "scv977"
},
"message_id": 62
}"#;
let _: Message = serde_json::from_str(json).unwrap();
}
}

View file

@ -6,4 +6,4 @@ use serde::{Deserialize, Serialize};
/// [The official docs](https://core.telegram.org/bots/api#writeaccessallowed).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct WriteAccessAllowed;
pub struct WriteAccessAllowed {}