Message struct skip serializing for none fields

This commit is contained in:
Oleg A 2023-03-18 18:35:53 +03:00
parent da00c9274b
commit 4d0fc03fa2
No known key found for this signature in database
GPG key ID: 5FE046817A9657C5

View file

@ -17,6 +17,7 @@ use crate::types::{
/// This object represents a message. /// This object represents a message.
/// ///
/// [The official docs](https://core.telegram.org/bots/api#message). /// [The official docs](https://core.telegram.org/bots/api#message).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Message { pub struct Message {
/// Unique message identifier inside this chat. /// Unique message identifier inside this chat.
@ -132,6 +133,7 @@ pub struct MessageCommon {
pub has_protected_content: bool, pub has_protected_content: bool,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageNewChatMembers { pub struct MessageNewChatMembers {
/// New members that were added to the group or supergroup and /// New members that were added to the group or supergroup and
@ -140,6 +142,7 @@ pub struct MessageNewChatMembers {
pub new_chat_members: Vec<User>, pub new_chat_members: Vec<User>,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageLeftChatMember { pub struct MessageLeftChatMember {
/// A member was removed from the group, information about them (this /// A member was removed from the group, information about them (this
@ -147,30 +150,35 @@ pub struct MessageLeftChatMember {
pub left_chat_member: User, pub left_chat_member: User,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageNewChatTitle { pub struct MessageNewChatTitle {
/// A chat title was changed to this value. /// A chat title was changed to this value.
pub new_chat_title: String, pub new_chat_title: String,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageNewChatPhoto { pub struct MessageNewChatPhoto {
/// A chat photo was change to this value. /// A chat photo was change to this value.
pub new_chat_photo: Vec<PhotoSize>, pub new_chat_photo: Vec<PhotoSize>,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct MessageDeleteChatPhoto { pub struct MessageDeleteChatPhoto {
/// Service message: the chat photo was deleted. /// Service message: the chat photo was deleted.
pub delete_chat_photo: True, pub delete_chat_photo: True,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct MessageGroupChatCreated { pub struct MessageGroupChatCreated {
/// Service message: the group has been created. /// Service message: the group has been created.
pub group_chat_created: True, pub group_chat_created: True,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct MessageSupergroupChatCreated { pub struct MessageSupergroupChatCreated {
/// Service message: the supergroup has been created. This field cant /// Service message: the supergroup has been created. This field cant
@ -181,6 +189,7 @@ pub struct MessageSupergroupChatCreated {
pub supergroup_chat_created: True, pub supergroup_chat_created: True,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct MessageChannelChatCreated { pub struct MessageChannelChatCreated {
/// Service message: the channel has been created. This field cant be /// Service message: the channel has been created. This field cant be
@ -191,6 +200,7 @@ pub struct MessageChannelChatCreated {
pub channel_chat_created: True, pub channel_chat_created: True,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageMessageAutoDeleteTimerChanged { pub struct MessageMessageAutoDeleteTimerChanged {
/// Service message: auto-delete timer settings changed in the chat. /// Service message: auto-delete timer settings changed in the chat.
@ -225,6 +235,7 @@ pub enum ChatMigration {
}, },
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessagePinned { pub struct MessagePinned {
/// Specified message was pinned. Note that the Message object in this /// Specified message was pinned. Note that the Message object in this
@ -234,6 +245,7 @@ pub struct MessagePinned {
pub pinned: Box<Message>, pub pinned: Box<Message>,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageInvoice { pub struct MessageInvoice {
/// Message is an invoice for a [payment], information about the /// Message is an invoice for a [payment], information about the
@ -244,6 +256,7 @@ pub struct MessageInvoice {
pub invoice: Invoice, pub invoice: Invoice,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageSuccessfulPayment { pub struct MessageSuccessfulPayment {
/// Message is a service message about a successful payment, /// Message is a service message about a successful payment,
@ -253,6 +266,7 @@ pub struct MessageSuccessfulPayment {
pub successful_payment: SuccessfulPayment, pub successful_payment: SuccessfulPayment,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageConnectedWebsite { pub struct MessageConnectedWebsite {
/// The domain name of the website on which the user has logged in. /// The domain name of the website on which the user has logged in.
@ -262,6 +276,7 @@ pub struct MessageConnectedWebsite {
pub connected_website: String, pub connected_website: String,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessagePassportData { pub struct MessagePassportData {
/// Telegram Passport data. /// Telegram Passport data.
@ -269,6 +284,7 @@ pub struct MessagePassportData {
} }
/// Information about forwarded message. /// Information about forwarded message.
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Forward { pub struct Forward {
/// Date the original message was sent in Unix time. /// Date the original message was sent in Unix time.
@ -336,6 +352,7 @@ pub enum MediaKind {
Migration(ChatMigration), Migration(ChatMigration),
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MediaAnimation { pub struct MediaAnimation {
/// Message is an animation, information about the animation. For /// Message is an animation, information about the animation. For
@ -376,6 +393,7 @@ pub struct MediaAudio {
pub media_group_id: Option<String>, pub media_group_id: Option<String>,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MediaContact { pub struct MediaContact {
/// Message is a shared contact, information about the contact. /// Message is a shared contact, information about the contact.
@ -401,6 +419,7 @@ pub struct MediaDocument {
pub media_group_id: Option<String>, pub media_group_id: Option<String>,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MediaGame { pub struct MediaGame {
/// Message is a game, information about the game. [More /// Message is a game, information about the game. [More
@ -410,6 +429,7 @@ pub struct MediaGame {
pub game: Game, pub game: Game,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MediaLocation { pub struct MediaLocation {
/// Message is a shared location, information about the location. /// Message is a shared location, information about the location.
@ -439,18 +459,21 @@ pub struct MediaPhoto {
pub media_group_id: Option<String>, pub media_group_id: Option<String>,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MediaPoll { pub struct MediaPoll {
/// Message is a native poll, information about the poll. /// Message is a native poll, information about the poll.
pub poll: Poll, pub poll: Poll,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MediaSticker { pub struct MediaSticker {
/// Message is a sticker, information about the sticker. /// Message is a sticker, information about the sticker.
pub sticker: Sticker, pub sticker: Sticker,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MediaText { pub struct MediaText {
/// For text messages, the actual UTF-8 text of the message, 0-4096 /// For text messages, the actual UTF-8 text of the message, 0-4096
@ -486,6 +509,7 @@ pub struct MediaVideo {
pub media_group_id: Option<String>, pub media_group_id: Option<String>,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MediaVideoNote { pub struct MediaVideoNote {
/// Message is a [video note], information about the video message. /// Message is a [video note], information about the video message.
@ -516,12 +540,14 @@ pub struct MediaVenue {
// Note: for backward compatibility telegram also sends `location` field, but we ignore it // Note: for backward compatibility telegram also sends `location` field, but we ignore it
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageDice { pub struct MessageDice {
/// Message is a dice with random value from 1 to 6. /// Message is a dice with random value from 1 to 6.
pub dice: Dice, pub dice: Dice,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageProximityAlertTriggered { pub struct MessageProximityAlertTriggered {
/// Service message. A user in the chat triggered another user's proximity /// Service message. A user in the chat triggered another user's proximity
@ -529,6 +555,7 @@ pub struct MessageProximityAlertTriggered {
pub proximity_alert_triggered: ProximityAlertTriggered, pub proximity_alert_triggered: ProximityAlertTriggered,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageWriteAccessAllowed { pub struct MessageWriteAccessAllowed {
/// Service message: the user allowed the bot added to the attachment menu /// Service message: the user allowed the bot added to the attachment menu
@ -536,66 +563,77 @@ pub struct MessageWriteAccessAllowed {
pub write_access_allowed: WriteAccessAllowed, pub write_access_allowed: WriteAccessAllowed,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageForumTopicCreated { pub struct MessageForumTopicCreated {
/// Service message: forum topic created. /// Service message: forum topic created.
pub forum_topic_created: ForumTopicCreated, pub forum_topic_created: ForumTopicCreated,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageForumTopicEdited { pub struct MessageForumTopicEdited {
/// Service message: forum topic edited. /// Service message: forum topic edited.
pub forum_topic_edited: ForumTopicEdited, pub forum_topic_edited: ForumTopicEdited,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageForumTopicClosed { pub struct MessageForumTopicClosed {
/// Service message: forum topic closed. /// Service message: forum topic closed.
pub forum_topic_closed: ForumTopicClosed, pub forum_topic_closed: ForumTopicClosed,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageForumTopicReopened { pub struct MessageForumTopicReopened {
/// Service message: forum topic reopened. /// Service message: forum topic reopened.
pub forum_topic_reopened: ForumTopicReopened, pub forum_topic_reopened: ForumTopicReopened,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageGeneralForumTopicHidden { pub struct MessageGeneralForumTopicHidden {
/// Service message: the 'General' forum topic hidden. /// Service message: the 'General' forum topic hidden.
pub general_forum_topic_hidden: GeneralForumTopicHidden, pub general_forum_topic_hidden: GeneralForumTopicHidden,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageGeneralForumTopicUnhidden { pub struct MessageGeneralForumTopicUnhidden {
/// Service message: the 'General' forum topic unhidden. /// Service message: the 'General' forum topic unhidden.
pub general_forum_topic_unhidden: GeneralForumTopicUnhidden, pub general_forum_topic_unhidden: GeneralForumTopicUnhidden,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageVideoChatScheduled { pub struct MessageVideoChatScheduled {
/// Service message: video chat scheduled /// Service message: video chat scheduled
pub video_chat_scheduled: VideoChatScheduled, pub video_chat_scheduled: VideoChatScheduled,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageVideoChatStarted { pub struct MessageVideoChatStarted {
/// Service message: video chat started. /// Service message: video chat started.
pub video_chat_started: VideoChatStarted, pub video_chat_started: VideoChatStarted,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageVideoChatEnded { pub struct MessageVideoChatEnded {
/// Service message: video chat ended. /// Service message: video chat ended.
pub video_chat_ended: VideoChatEnded, pub video_chat_ended: VideoChatEnded,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageVideoChatParticipantsInvited { pub struct MessageVideoChatParticipantsInvited {
/// Service message: new participants invited to a video chat. /// Service message: new participants invited to a video chat.
pub video_chat_participants_invited: VideoChatParticipantsInvited, pub video_chat_participants_invited: VideoChatParticipantsInvited,
} }
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageWebAppData { pub struct MessageWebAppData {
/// Service message: data sent by a Web App. /// Service message: data sent by a Web App.