diff options
author | HampusM <hampus@hampusmat.com> | 2023-04-15 18:26:29 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-05-09 19:51:02 +0200 |
commit | e762babd9e69400ccd178ba8946168640093eb63 (patch) | |
tree | e07a56940f0c4a3551c87afad80bb949969335c7 /src/event.rs | |
parent | da509c366972ac6d423f95732cd3d319a2265841 (diff) |
feat: add deserialization
Diffstat (limited to 'src/event.rs')
-rw-r--r-- | src/event.rs | 54 |
1 files changed, 54 insertions, 0 deletions
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<String, Utf8Error>; +} + +impl<'a> EventExt for Event<'a> +{ + fn describe(&self) -> Result<String, Utf8Error> + { + 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(), + }) + } +} |