Fix MessageId deserialization

This commit is contained in:
Maybe Waffle 2022-09-29 13:32:36 +04:00
parent f5a3b55435
commit 13e5ed8fb4

View file

@ -2,7 +2,25 @@ use serde::{Deserialize, Serialize};
/// A unique message identifier.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct MessageId(#[serde(rename = "message_id")] pub i32);
#[serde(from = "MessageIdRaw", into = "MessageIdRaw")]
pub struct MessageId(pub i32);
#[derive(Serialize, Deserialize)]
struct MessageIdRaw {
message_id: i32,
}
impl From<MessageIdRaw> for MessageId {
fn from(MessageIdRaw { message_id }: MessageIdRaw) -> Self {
MessageId(message_id)
}
}
impl From<MessageId> for MessageIdRaw {
fn from(MessageId(message_id): MessageId) -> Self {
MessageIdRaw { message_id }
}
}
#[cfg(test)]
mod tests {