From 902d33c4344f4e38c021ff20b2197ee1dfbd347f Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Sat, 16 Mar 2024 16:48:46 +0100 Subject: bind streaming codec to hyper 1.x --- aero-dav/src/calencoder.rs | 18 ++++++++++++++++-- aero-dav/src/error.rs | 19 +++++++++++++++++++ aero-dav/src/realization.rs | 4 ++-- aero-dav/src/xml.rs | 6 +++--- 4 files changed, 40 insertions(+), 7 deletions(-) (limited to 'aero-dav') diff --git a/aero-dav/src/calencoder.rs b/aero-dav/src/calencoder.rs index fff4d47..e00876d 100644 --- a/aero-dav/src/calencoder.rs +++ b/aero-dav/src/calencoder.rs @@ -393,7 +393,14 @@ impl QWrite for CompKind { for comp in many_comp.iter() { // Required: recursion in an async fn requires boxing // rustc --explain E0733 - Box::pin(comp.qwrite(xml)).await?; + // Cycle detected when computing type of ... + // For more information about this error, try `rustc --explain E0391`. + // https://github.com/rust-lang/rust/issues/78649 + #[inline(always)] + fn recurse<'a>(comp: &'a Comp, xml: &'a mut Writer) -> futures::future::BoxFuture<'a, Result<(), QError>> { + Box::pin(comp.qwrite(xml)) + } + recurse(comp, xml).await?; } Ok(()) } @@ -525,7 +532,14 @@ impl QWrite for CompFilterMatch { for comp_item in self.comp_filter.iter() { // Required: recursion in an async fn requires boxing // rustc --explain E0733 - Box::pin(comp_item.qwrite(xml)).await?; + // Cycle detected when computing type of ... + // For more information about this error, try `rustc --explain E0391`. + // https://github.com/rust-lang/rust/issues/78649 + #[inline(always)] + fn recurse<'a>(comp: &'a CompFilter, xml: &'a mut Writer) -> futures::future::BoxFuture<'a, Result<(), QError>> { + Box::pin(comp.qwrite(xml)) + } + recurse(comp_item, xml).await?; } Ok(()) } diff --git a/aero-dav/src/error.rs b/aero-dav/src/error.rs index f1b5cba..570f779 100644 --- a/aero-dav/src/error.rs +++ b/aero-dav/src/error.rs @@ -15,6 +15,25 @@ pub enum ParsingError { Int(std::num::ParseIntError), Eof } +impl std::fmt::Display for ParsingError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Recoverable => write!(f, "Recoverable"), + Self::MissingChild => write!(f, "Missing child"), + Self::MissingAttribute => write!(f, "Missing attribute"), + Self::NamespacePrefixAlreadyUsed => write!(f, "Namespace prefix already used"), + Self::WrongToken => write!(f, "Wrong token"), + Self::TagNotFound => write!(f, "Tag not found"), + Self::InvalidValue => write!(f, "Invalid value"), + Self::Utf8Error(_) => write!(f, "Utf8 Error"), + Self::QuickXml(_) => write!(f, "Quick XML error"), + Self::Chrono(_) => write!(f, "Chrono error"), + Self::Int(_) => write!(f, "Number parsing error"), + Self::Eof => write!(f, "Found EOF while expecting data"), + } + } +} +impl std::error::Error for ParsingError {} impl From for ParsingError { fn from(value: AttrError) -> Self { Self::QuickXml(value.into()) diff --git a/aero-dav/src/realization.rs b/aero-dav/src/realization.rs index 5781637..a7bbb16 100644 --- a/aero-dav/src/realization.rs +++ b/aero-dav/src/realization.rs @@ -11,8 +11,8 @@ impl xml::QRead for Disabled { } } impl xml::QWrite for Disabled { - async fn qwrite(&self, _xml: &mut xml::Writer) -> Result<(), quick_xml::Error> { - unreachable!(); + fn qwrite(&self, _xml: &mut xml::Writer) -> impl futures::Future> + Send { + async { unreachable!(); } } } diff --git a/aero-dav/src/xml.rs b/aero-dav/src/xml.rs index 1f8a6b1..e078c6f 100644 --- a/aero-dav/src/xml.rs +++ b/aero-dav/src/xml.rs @@ -12,19 +12,19 @@ pub const CAL_URN: &[u8] = b"urn:ietf:params:xml:ns:caldav"; pub const CARD_URN: &[u8] = b"urn:ietf:params:xml:ns:carddav"; // Async traits -pub trait IWrite = AsyncWrite + Unpin; +pub trait IWrite = AsyncWrite + Unpin + Send; pub trait IRead = AsyncBufRead + Unpin; // Serialization/Deserialization traits pub trait QWrite { - fn qwrite(&self, xml: &mut Writer) -> impl Future>; + fn qwrite(&self, xml: &mut Writer) -> impl Future> + Send; } pub trait QRead { fn qread(xml: &mut Reader) -> impl Future>; } // The representation of an XML node in Rust -pub trait Node = QRead + QWrite + std::fmt::Debug + PartialEq; +pub trait Node = QRead + QWrite + std::fmt::Debug + PartialEq + Sync; // --------------- -- cgit v1.2.3