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
use crate::*;

impl Tag {
    fn flattened(self) -> Self {
        Self {
            inner: self.inner.map(|x| x.flattened()),
            ..self
        }
    }
}

impl Content {
    fn unwrap(self) -> Vec<Content> {
        match self {
            Self::Nested(x) => x.flattened().0,
            Self::Tag(t)    => vec![Self::Tag(t.flattened())],
            c               => vec![c],
        }
    }
}

impl Xml {
    pub fn flattened(self) -> Self {
        let inner = self
            .0
            .into_iter()
            .map(Content::unwrap)
            .flatten()
            .collect();
        Self(inner)
    }
}