docx_rs/documents/elements/
section.rs1use super::*;
2use crate::documents::BuildXML;
3use crate::xml_builder::*;
4use std::io::Write;
5
6use serde::Serialize;
7
8#[derive(Debug, Clone, PartialEq, Serialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Section {
11 property: SectionProperty,
12}
13
14impl Section {
15 pub fn new() -> Section {
16 Default::default()
17 }
18}
19
20impl Default for Section {
21 fn default() -> Self {
22 Self {
23 property: SectionProperty::new(),
24 }
25 }
26}
27
28impl BuildXML for Section {
29 fn build_to<W: Write>(
30 &self,
31 stream: xml::writer::EventWriter<W>,
32 ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
33 let id = crate::generate_para_id();
34 XMLBuilder::from(stream)
35 .open_paragraph(&id)?
36 .open_paragraph_property()?
37 .add_child(&self.property)?
38 .close()?
39 .close()?
40 .into_inner()
41 }
42}
43
44#[cfg(test)]
45mod tests {
46
47 use super::*;
48 #[cfg(test)]
49 use pretty_assertions::assert_eq;
50 use std::str;
51
52 #[test]
53 fn test_section_property_default() {
54 let c = Section::new();
55 let b = c.build();
56 assert_eq!(
57 str::from_utf8(&b).unwrap(),
58 r#"<w:p w14:paraId="12345678"><w:pPr><w:sectPr><w:pgSz w:w="11906" w:h="16838" /><w:pgMar w:top="1985" w:right="1701" w:bottom="1701" w:left="1701" w:header="851" w:footer="992" w:gutter="0" /><w:cols w:space="425" w:num="1" /></w:sectPr></w:pPr></w:p>"#
59 );
60 }
61}