Skip to content

Commit

Permalink
use neater serde_with::skip_serializing_none logic (#31)
Browse files Browse the repository at this point in the history
use serde_with::skip_serializing_none to replace all instances of skip_serializing
  • Loading branch information
gabbifish authored Aug 20, 2019
1 parent 91944ab commit 7f060dc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ serde_derive = "1.0"
serde_json = "1.0"
serde_qs = "0.4"
serde_yaml = "0.8"
serde_with = "1.3.1"
slog = "2.4"
slog-term = "2.4"
sloggers = "0.3"
Expand Down
13 changes: 3 additions & 10 deletions src/endpoints/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,15 @@ impl<'a> Endpoint<DnsRecord, (), CreateDnsRecordParams<'a>> for CreateDnsRecord<
}
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Debug)]
pub struct CreateDnsRecordParams<'a> {
/// Time to live for DNS record. Value of 1 is 'automatic'
#[serde(skip_serializing_if = "Option::is_none")]
pub ttl: Option<u32>,
/// Used with some records like MX and SRV to determine priority.
/// If you do not supply a priority for an MX record, a default value of 0 will be set
#[serde(skip_serializing_if = "Option::is_none")]
pub priority: Option<u16>,
/// Whether the record is receiving the performance and security benefits of Cloudflare
#[serde(skip_serializing_if = "Option::is_none")]
pub proxied: Option<bool>,
/// DNS record name
pub name: &'a str,
Expand Down Expand Up @@ -92,21 +90,16 @@ pub enum ListDnsRecordsOrder {
Proxied,
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Debug, Default)]
pub struct ListDnsRecordsParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub record_type: Option<DnsContent>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub page: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub per_page: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub order: Option<ListDnsRecordsOrder>,
#[serde(skip_serializing_if = "Option::is_none")]
pub direction: Option<OrderDirection>,
#[serde(rename = "match", skip_serializing_if = "Option::is_none")]
#[serde(rename = "match")]
pub search_match: Option<SearchMatch>,
}

Expand Down
8 changes: 3 additions & 5 deletions src/endpoints/workerskv/write_bulk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ impl<'a> Endpoint<(), (), Vec<KeyValuePair>> for WriteBulk<'a> {
// default content-type is already application/json
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct KeyValuePair {
pub key: String,
pub value: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub expiration: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub expiration_ttl: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub expiration: Option<i64>,
pub expiration_ttl: Option<i64>,
pub base64: Option<bool>,
}

0 comments on commit 7f060dc

Please sign in to comment.