props: skip deserialization where it doesn't make sense

This commit is contained in:
Lennart
2024-11-04 21:14:54 +01:00
parent ff95d65d44
commit 0cf6e5cb92
5 changed files with 17 additions and 41 deletions

View File

@@ -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<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>,

View File

@@ -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)

View File

@@ -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<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>,

View File

@@ -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),

View File

@@ -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