aboutsummaryrefslogtreecommitdiff
path: root/src/event.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/event.rs')
-rw-r--r--src/event.rs54
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(),
+ })
+ }
+}