inline_xml/
flatten.rs

1use crate::*;
2
3impl Tag {
4    fn flattened(self) -> Self {
5        Self {
6            inner: self.inner.map(|x| x.flattened()),
7            ..self
8        }
9    }
10}
11
12impl Content {
13    fn unwrap(self) -> Vec<Content> {
14        match self {
15            Self::Nested(x) => x.flattened().0,
16            Self::Tag(t)    => vec![Self::Tag(t.flattened())],
17            c               => vec![c],
18        }
19    }
20}
21
22impl Xml {
23    pub fn flattened(self) -> Self {
24        let inner = self
25            .0
26            .into_iter()
27            .map(Content::unwrap)
28            .flatten()
29            .collect();
30        Self(inner)
31    }
32}