1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use strong_xml::{XmlRead, XmlWrite};
use crate::{__string_enum, __xml_test_suites};
#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
#[cfg_attr(test, derive(PartialEq))]
#[xml(tag = "w:tblW")]
pub struct TableWidth {
#[xml(attr = "w:w")]
pub value: Option<usize>,
#[xml(attr = "w:type")]
pub unit: Option<TableWidthUnit>,
}
impl From<usize> for TableWidth {
fn from(val: usize) -> Self {
TableWidth {
value: Some(val),
unit: None,
}
}
}
impl From<TableWidthUnit> for TableWidth {
fn from(val: TableWidthUnit) -> Self {
TableWidth {
value: None,
unit: Some(val),
}
}
}
impl From<(usize, TableWidthUnit)> for TableWidth {
fn from(val: (usize, TableWidthUnit)) -> Self {
TableWidth {
value: Some(val.0),
unit: Some(val.1),
}
}
}
#[derive(Debug, Clone)]
#[cfg_attr(test, derive(PartialEq))]
pub enum TableWidthUnit {
Auto,
Dxa,
Nil,
Pct,
}
__string_enum! {
TableWidthUnit {
Auto = "auto",
Dxa = "dxa",
Nil = "nil",
Pct = "pct",
}
}
__xml_test_suites!(
TableWidth,
TableWidth::default(),
"<w:tblW/>",
TableWidth::from(42),
r#"<w:tblW w:w="42"/>"#,
TableWidth::from(TableWidthUnit::Pct),
r#"<w:tblW w:type="pct"/>"#,
TableWidth::from((42, TableWidthUnit::Dxa)),
r#"<w:tblW w:w="42" w:type="dxa"/>"#,
);