diff --git a/crates/caldav/src/calendar/methods/mkcalendar.rs b/crates/caldav/src/calendar/methods/mkcalendar.rs index ebb2e61..5ec0f3c 100644 --- a/crates/caldav/src/calendar/methods/mkcalendar.rs +++ b/crates/caldav/src/calendar/methods/mkcalendar.rs @@ -3,14 +3,14 @@ use actix_web::web::{Data, Path}; use actix_web::HttpResponse; use rustical_store::auth::User; use rustical_store::{Calendar, CalendarStore}; -use rustical_xml::{Unit, XmlDeserialize, XmlDocument, XmlRootTag}; +use rustical_xml::{XmlDeserialize, XmlDocument, XmlRootTag}; use tracing::instrument; use tracing_actix_web::RootSpan; #[derive(XmlDeserialize, Clone, Debug)] pub struct Resourcetype { - calendar: Option, - collection: Option, + calendar: Option<()>, + collection: Option<()>, } #[derive(XmlDeserialize, Clone, Debug)] diff --git a/crates/caldav/src/calendar/methods/report/calendar_query.rs b/crates/caldav/src/calendar/methods/report/calendar_query.rs index aba9c8e..55da0e6 100644 --- a/crates/caldav/src/calendar/methods/report/calendar_query.rs +++ b/crates/caldav/src/calendar/methods/report/calendar_query.rs @@ -6,7 +6,7 @@ use rustical_dav::{ xml::{MultistatusElement, PropElement, PropfindType}, }; use rustical_store::{auth::User, calendar::UtcDateTime, CalendarObject, CalendarStore}; -use rustical_xml::{Unit, XmlDeserialize}; +use rustical_xml::XmlDeserialize; use crate::{ calendar_object::resource::{CalendarObjectProp, CalendarObjectResource}, @@ -27,7 +27,7 @@ pub(crate) struct TimeRangeElement { #[derive(XmlDeserialize, Clone, Debug, PartialEq)] #[allow(dead_code)] struct ParamFilterElement { - is_not_defined: Option, + is_not_defined: Option<()>, text_match: Option, #[xml(ty = "attr")] @@ -46,7 +46,7 @@ struct TextMatchElement { #[derive(XmlDeserialize, Clone, Debug, PartialEq)] #[allow(dead_code)] pub(crate) struct PropFilterElement { - is_not_defined: Option, + is_not_defined: Option<()>, time_range: Option, text_match: Option, #[xml(flatten)] @@ -57,7 +57,7 @@ pub(crate) struct PropFilterElement { #[allow(dead_code)] // https://datatracker.ietf.org/doc/html/rfc4791#section-9.7.1 pub(crate) struct CompFilterElement { - pub(crate) is_not_defined: Option, + pub(crate) is_not_defined: Option<()>, pub(crate) time_range: Option, #[xml(flatten)] pub(crate) prop_filter: Vec, diff --git a/crates/carddav/src/addressbook/methods/mkcol.rs b/crates/carddav/src/addressbook/methods/mkcol.rs index 518e1a5..87cc5da 100644 --- a/crates/carddav/src/addressbook/methods/mkcol.rs +++ b/crates/carddav/src/addressbook/methods/mkcol.rs @@ -2,14 +2,14 @@ use crate::Error; use actix_web::web::Path; use actix_web::{web::Data, HttpResponse}; use rustical_store::{auth::User, Addressbook, AddressbookStore}; -use rustical_xml::{Unit, XmlDeserialize, XmlDocument, XmlRootTag}; +use rustical_xml::{XmlDeserialize, XmlDocument, XmlRootTag}; use tracing::instrument; use tracing_actix_web::RootSpan; #[derive(XmlDeserialize, Clone, Debug, PartialEq)] pub struct Resourcetype { - addressbook: Option, - collection: Option, + addressbook: Option<()>, + collection: Option<()>, } #[derive(XmlDeserialize, Clone, Debug, PartialEq)] @@ -110,8 +110,8 @@ mod tests { set: PropElement { prop: MkcolAddressbookProp { resourcetype: Some(Resourcetype { - addressbook: Some(Unit), - collection: Some(Unit) + addressbook: Some(()), + collection: Some(()) }), displayname: Some("whoops".to_owned()), description: Some("okay".to_owned()) diff --git a/crates/xml/derive/src/de/de_enum.rs b/crates/xml/derive/src/de/de_enum.rs index 234cef9..e407cc0 100644 --- a/crates/xml/derive/src/de/de_enum.rs +++ b/crates/xml/derive/src/de/de_enum.rs @@ -117,7 +117,7 @@ impl Variant { quote! { #variant_name => { // Make sure that content is still consumed - ::rustical_xml::Unit::deserialize(reader, start, empty)?; + <() as ::rustical_xml::XmlDeserialize>::deserialize(reader, start, empty)?; Ok(Self::#ident) } } @@ -129,7 +129,7 @@ impl Variant { quote! { _ => { // Make sure that content is still consumed - ::rustical_xml::Unit::deserialize(reader, start, empty)?; + <() as ::rustical_xml::XmlDeserialize>::deserialize(reader, start, empty)?; Ok(Self::#ident) } } @@ -168,7 +168,7 @@ impl Variant { Fields::Unit => { quote! { // Make sure that content is still consumed - if let Ok(_) = ::rustical_xml::Unit::deserialize(reader, start, empty) { + if let Ok(_) = <() as ::rustical_xml::XmlDeserialize>::deserialize(reader, start, empty) { return Ok(Self::#ident); } } diff --git a/crates/xml/src/lib.rs b/crates/xml/src/lib.rs index 5b57e55..87b854f 100644 --- a/crates/xml/src/lib.rs +++ b/crates/xml/src/lib.rs @@ -12,32 +12,19 @@ pub use de::XmlRootTag; pub use se::XmlSerialize; pub use value::Value; -// impl XmlDeserialize for Option { -// fn deserialize( -// reader: &mut quick_xml::NsReader, -// start: &BytesStart, -// empty: bool, -// ) -> Result { -// Ok(Some(T::deserialize(reader, start, empty)?)) -// } -// } - -#[derive(Debug, Clone, PartialEq)] -pub struct Unit; - -impl XmlDeserialize for Unit { +impl XmlDeserialize for () { fn deserialize( reader: &mut quick_xml::NsReader, start: &BytesStart, empty: bool, ) -> Result { if empty { - return Ok(Unit); + return Ok(()); } let mut buf = Vec::new(); loop { match reader.read_event_into(&mut buf)? { - Event::End(e) if e.name() == start.name() => return Ok(Unit), + Event::End(e) if e.name() == start.name() => return Ok(()), Event::Eof => return Err(XmlDeError::Eof), _ => {} }; diff --git a/crates/xml/tests/de_enum.rs b/crates/xml/tests/de_enum.rs index 67dabba..022a47f 100644 --- a/crates/xml/tests/de_enum.rs +++ b/crates/xml/tests/de_enum.rs @@ -1,4 +1,4 @@ -use rustical_xml::{de::XmlDocument, Unit, XmlDeserialize, XmlRootTag}; +use rustical_xml::{de::XmlDocument, XmlDeserialize, XmlRootTag}; #[test] fn test_struct_tagged_enum() { @@ -78,7 +78,7 @@ fn test_tagged_enum_complex() { #[derive(Debug, XmlDeserialize, PartialEq)] struct Nice { - nice: Unit, + nice: (), } let asd = Propfind::parse_str( @@ -94,7 +94,6 @@ fn test_tagged_enum_complex() { "#, ) .unwrap(); - dbg!(asd); } #[test] diff --git a/crates/xml/tests/de_struct.rs b/crates/xml/tests/de_struct.rs index 1f10ca0..c8e6315 100644 --- a/crates/xml/tests/de_struct.rs +++ b/crates/xml/tests/de_struct.rs @@ -1,6 +1,6 @@ use rustical_xml::de::XmlDocument; use rustical_xml::XmlRootTag; -use rustical_xml::{Unit, Unparsed, XmlDeserialize}; +use rustical_xml::{Unparsed, XmlDeserialize}; use std::collections::HashSet; #[test] @@ -155,11 +155,11 @@ fn test_struct_ns() { #[xml(root = b"document", ns_strict)] struct Document { #[xml(ns = b"hello")] - child: Unit, + child: (), } let doc = Document::parse_str(r#""#).unwrap(); - assert_eq!(doc, Document { child: Unit }); + assert_eq!(doc, Document { child: () }); } #[test] @@ -168,7 +168,7 @@ fn test_struct_attr() { #[xml(root = b"document", ns_strict)] struct Document { #[xml(ns = b"hello")] - child: Unit, + child: (), #[xml(ty = "attr", default = "Default::default")] test: String, #[xml(ty = "attr")] @@ -182,7 +182,7 @@ fn test_struct_attr() { assert_eq!( doc, Document { - child: Unit, + child: (), test: "hello!".to_owned(), number: 2 }