From e762babd9e69400ccd178ba8946168640093eb63 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 15 Apr 2023 18:26:29 +0200 Subject: feat: add deserialization --- src/event.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/event.rs (limited to 'src/event.rs') diff --git a/src/event.rs b/src/event.rs new file mode 100644 index 0000000..ae0624d --- /dev/null +++ b/src/event.rs @@ -0,0 +1,54 @@ +use std::str::Utf8Error; + +use quick_xml::events::Event; + +#[allow(clippy::module_name_repetitions)] +pub trait EventExt +{ + fn describe(&self) -> Result; +} + +impl<'a> EventExt for Event<'a> +{ + fn describe(&self) -> Result + { + Ok(match self { + Event::Start(start) => { + format!( + "tag start with name \"{}\"", + std::str::from_utf8(start.name().as_ref())? + ) + } + Event::End(end) => { + format!( + "tag end with name \"{}\"", + std::str::from_utf8(end.name().as_ref())? + ) + } + Event::Empty(start) => { + format!( + "empty tag with name \"{}\"", + std::str::from_utf8(start.name().as_ref())? + ) + } + Event::Text(text) => { + format!("text \"{}\"", std::str::from_utf8(text)?) + } + Event::Comment(comment) => { + format!("comment \"{}\"", std::str::from_utf8(comment)?) + } + Event::CData(cdata) => { + format!("cdata \"{}\"", std::str::from_utf8(cdata)?) + } + Event::Decl(_) => "XML declaration".to_string(), + Event::PI(processing_instruction) => { + format!( + "processing instruction \"{}\"", + std::str::from_utf8(processing_instruction)? + ) + } + Event::DocType(_) => "doctype".to_string(), + Event::Eof => "end of file".to_string(), + }) + } +} -- cgit v1.2.3-18-g5258