From e88e448179239fcc41aa03efcbfb2cc2ab0c922e Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 1 Mar 2024 08:32:02 +0100 Subject: Simplify code --- src/dav/calencoder.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/dav/calencoder.rs') diff --git a/src/dav/calencoder.rs b/src/dav/calencoder.rs index aabdf36..378d2bd 100644 --- a/src/dav/calencoder.rs +++ b/src/dav/calencoder.rs @@ -8,10 +8,7 @@ use quick_xml::writer::{ElementWriter, Writer}; use quick_xml::name::PrefixDeclaration; use tokio::io::AsyncWrite; -pub struct CalCtx { - root: bool -} -impl Context for CalCtx { +impl Context for CalExtension { fn child(&self) -> Self { Self { root: false } } @@ -23,7 +20,8 @@ impl Context for CalCtx { err.write(xml, self.child()).await } } -impl CalCtx { + +impl CalExtension { fn create_ns_element(&self, ns: &str, name: &str) -> BytesStart { let mut start = BytesStart::new(format!("{}:{}", ns, name)); if self.root { @@ -37,8 +35,8 @@ impl CalCtx { } } -impl QuickWritable for Violation { - async fn write(&self, xml: &mut Writer, ctx: CalCtx) -> Result<(), QError> { +impl QuickWritable for Violation { + async fn write(&self, xml: &mut Writer, ctx: CalExtension) -> Result<(), QError> { match self { Self::SupportedFilter => { let start = ctx.create_cal_element("supported-filter"); @@ -70,11 +68,11 @@ mod tests { let mut tokio_buffer = tokio::io::BufWriter::new(&mut buffer); let mut writer = Writer::new_with_indent(&mut tokio_buffer, b' ', 4); - let res: Error = Error(vec![ + let res = Error(vec![ DavViolation::Extension(Violation::SupportedFilter), ]); - res.write(&mut writer, CalCtx{ root: true }).await.expect("xml serialization"); + res.write(&mut writer, CalExtension { root: true }).await.expect("xml serialization"); tokio_buffer.flush().await.expect("tokio buffer flush"); let expected = r#" -- cgit v1.2.3