docx_rs/documents/
build_xml.rs

1use crate::xml_builder::XMLBuilder;
2use std::io::Write;
3
4pub trait BuildXML {
5    /// Write XML to the output stream.
6    #[doc(hidden)]
7    fn build_to<W: Write>(
8        &self,
9        stream: xml::writer::EventWriter<W>,
10    ) -> xml::writer::Result<xml::writer::EventWriter<W>>;
11
12    #[doc(hidden)]
13    fn build(&self) -> Vec<u8> {
14        self.build_to(XMLBuilder::new(Vec::new()).into_inner().unwrap())
15            .expect("should write to buf")
16            .into_inner()
17    }
18}
19
20impl<'a, T: BuildXML> BuildXML for &'a T {
21    /// Building XML from `&T` is the same as from `T`.
22    fn build_to<W: Write>(
23        &self,
24        stream: xml::writer::EventWriter<W>,
25    ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
26        (*self).build_to(stream)
27    }
28}
29
30impl<T: BuildXML> BuildXML for Box<T> {
31    /// Building XML from `Box<T>` is the same as from `T`.
32    fn build_to<W: Write>(
33        &self,
34        stream: xml::writer::EventWriter<W>,
35    ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
36        (**self).build_to(stream)
37    }
38}