blob: ae0624d026a985ddd756312109f0215876d92af6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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(),
})
}
}
|