docx_rs/documents/elements/
table_indent.rs

1use serde::Serialize;
2use std::io::Write;
3
4use crate::documents::BuildXML;
5use crate::types::*;
6use crate::xml_builder::*;
7
8#[derive(Debug, Clone, PartialEq, Serialize)]
9#[serde(rename_all = "camelCase")]
10pub struct TableIndent {
11    width: i32,
12    width_type: WidthType,
13}
14
15impl TableIndent {
16    pub fn new(width: i32, width_type: WidthType) -> TableIndent {
17        TableIndent { width, width_type }
18    }
19}
20
21impl BuildXML for TableIndent {
22    fn build_to<W: Write>(
23        &self,
24        stream: xml::writer::EventWriter<W>,
25    ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
26        XMLBuilder::from(stream)
27            .table_indent(self.width, self.width_type)?
28            .into_inner()
29    }
30}
31
32#[cfg(test)]
33mod tests {
34
35    use super::*;
36    #[cfg(test)]
37    use pretty_assertions::assert_eq;
38    use std::str;
39
40    #[test]
41    fn test_table_indent() {
42        let b = TableIndent::new(20, WidthType::Dxa).build();
43        assert_eq!(
44            str::from_utf8(&b).unwrap(),
45            r#"<w:tblInd w:w="20" w:type="dxa" />"#
46        );
47    }
48}