xsd_parser/xml/
value.rs

1use std::fmt::{Debug, Formatter, Result as FmtResult};
2
3use quick_xml::events::{BytesCData, BytesText};
4
5use crate::models::format_utf8_slice;
6
7use super::Element;
8
9/// Represents unstructured XML data.
10///
11/// This is mainly used to store the data contained by an [`Element`].
12#[derive(Clone, Eq, PartialEq)]
13pub enum Value<'a> {
14    /// A child [`Element`].
15    Element(Element<'a>),
16
17    /// A comment in the XML code.
18    Comment(BytesText<'a>),
19
20    /// A CDATA value.
21    CData(BytesCData<'a>),
22
23    /// A simple text value.
24    Text(BytesText<'a>),
25}
26
27impl Debug for Value<'_> {
28    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
29        match self {
30            Self::Element(element) => element.fmt(f)?,
31            Self::Comment(comment) => {
32                write!(f, "Comment(\"")?;
33                format_utf8_slice(comment, f)?;
34                write!(f, "\")")?;
35            }
36            Self::CData(cdata) => {
37                write!(f, "CData(\"")?;
38                format_utf8_slice(cdata, f)?;
39                write!(f, "\")")?;
40            }
41            Self::Text(text) => {
42                write!(f, "Text(\"")?;
43                format_utf8_slice(text, f)?;
44                write!(f, "\")")?;
45            }
46        }
47
48        Ok(())
49    }
50}