mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-11 04:21:12 +01:00
Use serde(default)
where applicable
This commit is contained in:
parent
19bcd8a6ba
commit
3047bea3ab
5 changed files with 5 additions and 14 deletions
|
@ -245,16 +245,11 @@ pub(crate) mod serde_opt_date_from_unix_timestamp {
|
|||
.map(|timestamp| DateTime::from_utc(NaiveDateTime::from_timestamp(timestamp, 0), Utc)))
|
||||
}
|
||||
|
||||
pub(crate) fn none<T>() -> Option<T> {
|
||||
None
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Struct {
|
||||
#[serde(with = "crate::types::serde_opt_date_from_unix_timestamp")]
|
||||
#[serde(default = "crate::types::serde_opt_date_from_unix_timestamp::none")]
|
||||
#[serde(default, with = "crate::types::serde_opt_date_from_unix_timestamp")]
|
||||
date: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,7 @@ pub struct ChatInviteLink {
|
|||
pub name: Option<String>,
|
||||
/// Point in time when the link will expire or has been
|
||||
/// expired
|
||||
#[serde(with = "crate::types::serde_opt_date_from_unix_timestamp")]
|
||||
#[serde(default = "crate::types::serde_opt_date_from_unix_timestamp::none")]
|
||||
#[serde(default, with = "crate::types::serde_opt_date_from_unix_timestamp")]
|
||||
pub expire_date: Option<DateTime<Utc>>,
|
||||
/// Maximum number of users that can be members of the chat simultaneously
|
||||
/// after joining the chat via this invite link; 1-99999
|
||||
|
|
|
@ -85,8 +85,7 @@ pub struct MessageCommon {
|
|||
pub reply_to_message: Option<Box<Message>>,
|
||||
|
||||
/// Date the message was last edited in Unix time.
|
||||
#[serde(with = "crate::types::serde_opt_date_from_unix_timestamp")]
|
||||
#[serde(default = "crate::types::serde_opt_date_from_unix_timestamp::none")]
|
||||
#[serde(default, with = "crate::types::serde_opt_date_from_unix_timestamp")]
|
||||
pub edit_date: Option<DateTime<Utc>>,
|
||||
|
||||
#[serde(flatten)]
|
||||
|
|
|
@ -51,8 +51,7 @@ pub struct Poll {
|
|||
pub open_period: Option<u16>,
|
||||
|
||||
/// Point in time when the poll will be automatically closed.
|
||||
#[serde(with = "crate::types::serde_opt_date_from_unix_timestamp")]
|
||||
#[serde(default = "crate::types::serde_opt_date_from_unix_timestamp::none")]
|
||||
#[serde(default, with = "crate::types::serde_opt_date_from_unix_timestamp")]
|
||||
pub close_date: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
|
|
|
@ -22,8 +22,7 @@ pub struct WebhookInfo {
|
|||
|
||||
/// Time of the most recent error that happened when trying to
|
||||
/// deliver an update via webhook.
|
||||
#[serde(with = "crate::types::serde_opt_date_from_unix_timestamp")]
|
||||
#[serde(default = "crate::types::serde_opt_date_from_unix_timestamp::none")]
|
||||
#[serde(default, with = "crate::types::serde_opt_date_from_unix_timestamp")]
|
||||
pub last_error_date: Option<DateTime<Utc>>,
|
||||
|
||||
/// Error message in human-readable format for the most recent error that
|
||||
|
|
Loading…
Reference in a new issue