1use super::clone::elements_to_owned;
22use super::{Alignment, AttributeMap, Element};
23use std::num::NonZeroU32;
24
25#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
26#[serde(rename_all = "kebab-case")]
27pub struct Table<'t> {
28 #[serde(rename = "type")]
29 pub table_type: TableType,
30 pub attributes: AttributeMap<'t>,
31 pub rows: Vec<TableRow<'t>>,
32}
33
34impl Table<'_> {
35 pub fn to_owned(&self) -> Table<'static> {
36 Table {
37 table_type: self.table_type,
38 attributes: self.attributes.to_owned(),
39 rows: self.rows.iter().map(|row| row.to_owned()).collect(),
40 }
41 }
42}
43
44#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq)]
45#[serde(rename_all = "kebab-case")]
46pub enum TableType {
47 Simple,
48 Advanced,
49}
50
51#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
52#[serde(rename_all = "kebab-case")]
53pub struct TableRow<'t> {
54 pub attributes: AttributeMap<'t>,
55 pub cells: Vec<TableCell<'t>>,
56}
57
58impl TableRow<'_> {
59 pub fn to_owned(&self) -> TableRow<'static> {
60 TableRow {
61 attributes: self.attributes.to_owned(),
62 cells: self.cells.iter().map(|cell| cell.to_owned()).collect(),
63 }
64 }
65}
66
67#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
68#[serde(rename_all = "kebab-case")]
69pub struct TableCell<'t> {
70 pub header: bool,
71 pub column_span: NonZeroU32,
72 pub align: Option<Alignment>,
73 pub attributes: AttributeMap<'t>,
74 pub elements: Vec<Element<'t>>,
75}
76
77impl TableCell<'_> {
78 pub fn to_owned(&self) -> TableCell<'static> {
79 TableCell {
80 header: self.header,
81 column_span: self.column_span,
82 align: self.align,
83 attributes: self.attributes.to_owned(),
84 elements: elements_to_owned(&self.elements),
85 }
86 }
87}
88
89#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
90#[serde(rename_all = "kebab-case")]
91pub enum TableItem<'t> {
92 Row(TableRow<'t>),
93 Cell(TableCell<'t>),
94}
95
96impl TableItem<'_> {
97 pub fn to_owned(&self) -> TableItem<'static> {
98 match self {
99 TableItem::Row(row) => TableItem::Row(row.to_owned()),
100 TableItem::Cell(cell) => TableItem::Cell(cell.to_owned()),
101 }
102 }
103}