docx_rs/documents/elements/
paragraph_property_default.rs1use 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 ParagraphPropertyDefault {
11 paragraph_property: ParagraphProperty,
12}
13
14impl ParagraphPropertyDefault {
15 pub fn new() -> Self {
16 Default::default()
17 }
18
19 pub fn line_spacing(mut self, spacing: LineSpacing) -> Self {
20 self.paragraph_property = self.paragraph_property.line_spacing(spacing);
21 self
22 }
23
24 pub fn paragraph_property(mut self, p: ParagraphProperty) -> Self {
25 self.paragraph_property = p;
26 self
27 }
28}
29
30impl Default for ParagraphPropertyDefault {
31 fn default() -> Self {
32 let paragraph_property = ParagraphProperty::new();
33 ParagraphPropertyDefault { paragraph_property }
34 }
35}
36
37impl BuildXML for ParagraphPropertyDefault {
38 fn build_to<W: Write>(
39 &self,
40 stream: xml::writer::EventWriter<W>,
41 ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
42 XMLBuilder::from(stream)
43 .open_paragraph_property_default()?
44 .add_child(&self.paragraph_property)?
45 .close()?
46 .into_inner()
47 }
48}
49
50mod tests {
51
52 #[allow(unused_imports)]
53 use super::*;
54
55 #[cfg(test)]
56 use pretty_assertions::assert_eq;
57
58 #[test]
59 fn test_build() {
60 let c = ParagraphPropertyDefault::new();
61 let b = c.build();
62 assert_eq!(
63 std::str::from_utf8(&b).unwrap(),
64 r#"<w:pPrDefault><w:pPr><w:rPr /></w:pPr></w:pPrDefault>"#
65 );
66 }
67}