From 0cf6e5cb929d93e1bf5482515bbfba857491b6c3 Mon Sep 17 00:00:00 2001 From: Lennart <18233294+lennart-k@users.noreply.github.com> Date: Mon, 4 Nov 2024 21:14:54 +0100 Subject: [PATCH] props: skip deserialization where it doesn't make sense --- crates/caldav/src/calendar/prop.rs | 10 ++++---- crates/caldav/src/calendar/resource.rs | 2 ++ crates/carddav/src/addressbook/prop.rs | 14 +++++----- crates/carddav/src/addressbook/resource.rs | 2 ++ crates/dav/src/xml/resourcetype.rs | 30 +--------------------- 5 files changed, 17 insertions(+), 41 deletions(-) diff --git a/crates/caldav/src/calendar/prop.rs b/crates/caldav/src/calendar/prop.rs index 074e2b6..e1c5922 100644 --- a/crates/caldav/src/calendar/prop.rs +++ b/crates/caldav/src/calendar/prop.rs @@ -32,14 +32,14 @@ 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, @@ -47,14 +47,14 @@ pub enum ReportMethod { 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, @@ -69,7 +69,7 @@ impl From 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, diff --git a/crates/caldav/src/calendar/resource.rs b/crates/caldav/src/calendar/resource.rs index 01031aa..2a7eb53 100644 --- a/crates/caldav/src/calendar/resource.rs +++ b/crates/caldav/src/calendar/resource.rs @@ -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) diff --git a/crates/carddav/src/addressbook/prop.rs b/crates/carddav/src/addressbook/prop.rs index b1e36ee..cd6ff86 100644 --- a/crates/carddav/src/addressbook/prop.rs +++ b/crates/carddav/src/addressbook/prop.rs @@ -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")] @@ -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")] @@ -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, @@ -62,7 +62,7 @@ impl From 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, diff --git a/crates/carddav/src/addressbook/resource.rs b/crates/carddav/src/addressbook/resource.rs index b2e56c0..cc929b7 100644 --- a/crates/carddav/src/addressbook/resource.rs +++ b/crates/carddav/src/addressbook/resource.rs @@ -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), diff --git a/crates/dav/src/xml/resourcetype.rs b/crates/dav/src/xml/resourcetype.rs index 61da53f..ab9d60c 100644 --- a/crates/dav/src/xml/resourcetype.rs +++ b/crates/dav/src/xml/resourcetype.rs @@ -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(self, mut map: A) -> Result - where - A: MapAccess<'de>, - { - while map.next_key::()?.is_some() {} - Ok(Resourcetype(&[])) - } -} - -impl<'de> Deserialize<'de> for Resourcetype { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - deserializer.deserialize_map(ResourcetypeVisitor) - } -} - impl Serialize for Resourcetype { fn serialize(&self, serializer: S) -> Result where