docx_rs/documents/elements/
table_cell_width.rs1use serde::Serialize;
2use std::io::Write;
3
4use crate::documents::BuildXML;
5use crate::types::*;
6use crate::xml_builder::*;
7
8#[derive(Serialize, Debug, Clone, PartialEq)]
9#[serde(rename_all = "camelCase")]
10pub struct TableCellWidth {
11 width: usize,
12 width_type: WidthType,
13}
14
15impl TableCellWidth {
16 pub fn new(width: usize, width_type: WidthType) -> TableCellWidth {
17 TableCellWidth { width, width_type }
18 }
19}
20
21impl BuildXML for TableCellWidth {
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_cell_width(self.width as i32, 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_width() {
42 let b = TableCellWidth::new(20, WidthType::Dxa).build();
43 assert_eq!(
44 str::from_utf8(&b).unwrap(),
45 r#"<w:tcW w:w="20" w:type="dxa" />"#
46 );
47 }
48}