docx_rs/documents/elements/
run_property_default.rs

1use serde::Serialize;
2use std::io::Write;
3
4use super::*;
5use crate::documents::BuildXML;
6use crate::xml_builder::*;
7
8#[derive(Debug, Clone, PartialEq, Serialize)]
9#[serde(rename_all = "camelCase")]
10pub struct RunPropertyDefault {
11    run_property: RunProperty,
12}
13
14impl RunPropertyDefault {
15    pub fn new() -> RunPropertyDefault {
16        Default::default()
17    }
18
19    pub fn size(mut self, size: usize) -> Self {
20        self.run_property = self.run_property.size(size);
21        self
22    }
23
24    pub fn spacing(mut self, spacing: i32) -> Self {
25        self.run_property = self.run_property.spacing(spacing);
26        self
27    }
28
29    pub fn fonts(mut self, font: RunFonts) -> Self {
30        self.run_property = self.run_property.fonts(font);
31        self
32    }
33
34    pub(crate) fn run_property(mut self, p: RunProperty) -> Self {
35        self.run_property = p;
36        self
37    }
38}
39
40impl Default for RunPropertyDefault {
41    fn default() -> Self {
42        let run_property = RunProperty::new();
43        RunPropertyDefault { run_property }
44    }
45}
46
47impl BuildXML for RunPropertyDefault {
48    fn build_to<W: Write>(
49        &self,
50        stream: xml::writer::EventWriter<W>,
51    ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
52        XMLBuilder::from(stream)
53            .open_run_property_default()?
54            .add_child(&self.run_property)?
55            .close()?
56            .into_inner()
57    }
58}
59
60#[cfg(test)]
61mod tests {
62
63    use super::*;
64    #[cfg(test)]
65    use pretty_assertions::assert_eq;
66    use std::str;
67
68    #[test]
69    fn test_build() {
70        let c = RunPropertyDefault::new();
71        let b = c.build();
72        assert_eq!(
73            str::from_utf8(&b).unwrap(),
74            r#"<w:rPrDefault><w:rPr /></w:rPrDefault>"#
75        );
76    }
77}