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(),
})
}
}