1use std::io::BufRead;
2
3use quick_xml::{events::BytesStart, name::ResolveResult};
4
5use crate::{NamespaceOwned, XmlDeserialize, XmlError};
6
7#[derive(Debug, Clone, PartialEq, Eq, Hash)]
8pub struct Unparsed(pub Option<NamespaceOwned>, pub String);
9
10impl Unparsed {
11 #[must_use]
12 pub const fn ns(&self) -> Option<&NamespaceOwned> {
13 self.0.as_ref()
14 }
15
16 #[must_use]
17 pub const fn tag_name(&self) -> &str {
18 self.1.as_str()
19 }
20}
21
22impl XmlDeserialize for Unparsed {
23 fn deserialize<R: BufRead>(
24 reader: &mut quick_xml::NsReader<R>,
25 start: &BytesStart,
26 empty: bool,
27 ) -> Result<Self, XmlError> {
28 if !empty {
30 let mut buf = vec![];
31 reader.read_to_end_into(start.name(), &mut buf)?;
32 }
33 let (ns, tag_name) = reader.resolver().resolve_element(start.name());
34 let ns: Option<NamespaceOwned> = match ns {
35 ResolveResult::Bound(ns) => Some(ns.into()),
36 ResolveResult::Unbound | ResolveResult::Unknown(_) => None,
37 };
38 let tag_name = String::from_utf8_lossy(tag_name.as_ref()).to_string();
39 Ok(Self(ns, tag_name))
40 }
41}