Skip to content

Commit

Permalink
props: skip deserialization where it doesn't make sense
Browse files Browse the repository at this point in the history
  • Loading branch information
lennart-k committed Nov 4, 2024
1 parent ff95d65 commit 0cf6e5c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 41 deletions.
10 changes: 5 additions & 5 deletions crates/caldav/src/calendar/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,29 @@ impl Default for CalendarData {
}
}

#[derive(Debug, Clone, Deserialize, Serialize, Default, PartialEq)]
#[derive(Debug, Clone, Serialize, Default, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub struct SupportedCalendarData {
#[serde(rename = "C:calendar-data", alias = "calendar-data")]
calendar_data: CalendarData,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Clone, Serialize, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub enum ReportMethod {
CalendarQuery,
CalendarMultiget,
SyncCollection,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Clone, Serialize, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub struct ReportWrapper {
#[serde(rename = "$value")]
report: ReportMethod,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Clone, Serialize, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub struct SupportedReportWrapper {
report: ReportWrapper,
Expand All @@ -69,7 +69,7 @@ impl From<ReportMethod> for SupportedReportWrapper {
}

// RFC 3253 section-3.1.5
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Clone, Serialize, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub struct SupportedReportSet {
supported_report: Vec<SupportedReportWrapper>,
Expand Down
2 changes: 2 additions & 0 deletions crates/caldav/src/calendar/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ pub enum CalendarProp {
rename = "C:supported-calendar-data",
alias = "supported-calendar-data"
)]
#[serde(skip_deserializing)]
SupportedCalendarData(SupportedCalendarData),
MaxResourceSize(i64),
#[serde(skip_deserializing)]
SupportedReportSet(SupportedReportSet),

// Collection Synchronization (RFC 6578)
Expand Down
14 changes: 7 additions & 7 deletions crates/carddav/src/addressbook/prop.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use serde::Serialize;

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Clone, Serialize, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub struct AddressDataType {
#[serde(rename = "@content-type")]
Expand All @@ -9,7 +9,7 @@ pub struct AddressDataType {
pub version: String,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Clone, Serialize, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub struct SupportedAddressData {
#[serde(rename = "CARD:address-data-type", alias = "address-data-type")]
Expand All @@ -33,21 +33,21 @@ impl Default for SupportedAddressData {
}
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Clone, Serialize, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub enum ReportMethod {
AddressbookMultiget,
SyncCollection,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Clone, Serialize, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub struct ReportWrapper {
#[serde(rename = "$value")]
report: ReportMethod,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Clone, Serialize, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub struct SupportedReportWrapper {
report: ReportWrapper,
Expand All @@ -62,7 +62,7 @@ impl From<ReportMethod> for SupportedReportWrapper {
}

// RFC 3253 section-3.1.5
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Clone, Serialize, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub struct SupportedReportSet {
supported_report: Vec<SupportedReportWrapper>,
Expand Down
2 changes: 2 additions & 0 deletions crates/carddav/src/addressbook/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ pub enum AddressbookProp {
rename = "CARD:supported-address-data",
alias = "supported-address-data"
)]
#[serde(skip_deserializing)]
SupportedAddressData(SupportedAddressData),
#[serde(skip_deserializing)]
SupportedReportSet(SupportedReportSet),
MaxResourceSize(i64),

Expand Down
30 changes: 1 addition & 29 deletions crates/dav/src/xml/resourcetype.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,9 @@
use serde::de::{MapAccess, Visitor};
use serde::ser::SerializeMap;
use serde::{Deserialize, Serialize};
use serde::Serialize;

#[derive(Debug, Clone, PartialEq)]
pub struct Resourcetype(pub &'static [&'static str]);

struct ResourcetypeVisitor;

impl<'de> Visitor<'de> for ResourcetypeVisitor {
type Value = Resourcetype;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("TagList")
}

fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
where
A: MapAccess<'de>,
{
while map.next_key::<String>()?.is_some() {}
Ok(Resourcetype(&[]))
}
}

impl<'de> Deserialize<'de> for Resourcetype {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
deserializer.deserialize_map(ResourcetypeVisitor)
}
}

impl Serialize for Resourcetype {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down

0 comments on commit 0cf6e5c

Please sign in to comment.