use super::error::ParsingError; use super::types as dav; use super::versioningtypes::*; use super::xml::{IRead, QRead, Reader, DAV_URN}; // -- extensions --- impl QRead for PropertyRequest { async fn qread(xml: &mut Reader) -> Result { if xml .maybe_open(DAV_URN, "supported-report-set") .await? .is_some() { xml.close().await?; return Ok(Self::SupportedReportSet); } return Err(ParsingError::Recoverable); } } impl QRead> for Property { async fn qread(xml: &mut Reader) -> Result { if xml .maybe_open(DAV_URN, "supported-report-set") .await? .is_some() { let supported_reports = xml.collect().await?; xml.close().await?; return Ok(Property::SupportedReportSet(supported_reports)); } Err(ParsingError::Recoverable) } } impl QRead> for SupportedReport { async fn qread(xml: &mut Reader) -> Result { xml.open(DAV_URN, "supported-report").await?; let r = xml.find().await?; xml.close().await?; Ok(SupportedReport(r)) } } impl QRead> for ReportName { async fn qread(xml: &mut Reader) -> Result { xml.open(DAV_URN, "report").await?; let final_result = if xml.maybe_open(DAV_URN, "version-tree").await?.is_some() { xml.close().await?; Ok(ReportName::VersionTree) } else if xml.maybe_open(DAV_URN, "expand-property").await?.is_some() { xml.close().await?; Ok(ReportName::ExpandProperty) } else { let x = match xml.maybe_find().await? { Some(v) => v, None => return Err(ParsingError::MissingChild), }; Ok(ReportName::Extension(x)) //E::ReportTypeName::qread(xml).await.map(ReportName::Extension) }; xml.close().await?; final_result } } impl QRead> for Report { async fn qread(xml: &mut Reader) -> Result { if xml.maybe_open(DAV_URN, "version-tree").await?.is_some() { xml.close().await?; tracing::warn!("version-tree is not implemented, skipping"); Ok(Report::VersionTree) } else if xml.maybe_open(DAV_URN, "expand-property").await?.is_some() { xml.close().await?; tracing::warn!("expand-property is not implemented, skipping"); Ok(Report::ExpandProperty) } else { E::ReportType::qread(xml).await.map(Report::Extension) } } } impl QRead for Limit { async fn qread(xml: &mut Reader) -> Result { xml.open(DAV_URN, "limit").await?; let nres = xml.find().await?; xml.close().await?; Ok(Limit(nres)) } } impl QRead for NResults { async fn qread(xml: &mut Reader) -> Result { xml.open(DAV_URN, "nresults").await?; let sz = xml.tag_string().await?.parse::()?; xml.close().await?; Ok(NResults(sz)) } } #[cfg(test)] mod tests { use super::*; use crate::xml::Node; async fn deserialize>(src: &str) -> T { let mut rdr = Reader::new(quick_xml::NsReader::from_reader(src.as_bytes())) .await .unwrap(); rdr.find().await.unwrap() } #[tokio::test] async fn nresults() { let expected = NResults(100); let src = r#"100"#; let got = deserialize::(src).await; assert_eq!(got, expected); } #[tokio::test] async fn limit() { let expected = Limit(NResults(1024)); let src = r#" 1024 "#; let got = deserialize::(src).await; assert_eq!(got, expected); } }