docx_reader/documents/
footer.rs

1use serde::ser::{SerializeStruct, Serializer};
2use serde::Serialize;
3
4use super::*;
5
6#[derive(Debug, Clone, PartialEq, Serialize, Default)]
7#[serde(rename_all = "camelCase")]
8pub struct Footer {
9	pub has_numbering: bool,
10	pub children: Vec<FooterChild>,
11}
12
13impl Footer {
14	pub fn new() -> Footer {
15		Default::default()
16	}
17
18	pub fn add_paragraph(mut self, p: Paragraph) -> Self {
19		if p.has_numbering {
20			self.has_numbering = true
21		}
22		self.children.push(FooterChild::Paragraph(Box::new(p)));
23		self
24	}
25
26	pub fn add_table(mut self, t: Table) -> Self {
27		if t.has_numbering {
28			self.has_numbering = true
29		}
30		self.children.push(FooterChild::Table(Box::new(t)));
31		self
32	}
33}
34
35#[derive(Debug, Clone, PartialEq)]
36pub enum FooterChild {
37	Paragraph(Box<Paragraph>),
38	Table(Box<Table>),
39}
40
41impl Serialize for FooterChild {
42	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
43	where
44		S: Serializer,
45	{
46		match *self {
47			FooterChild::Paragraph(ref p) => {
48				let mut t = serializer.serialize_struct("Paragraph", 2)?;
49				t.serialize_field("type", "paragraph")?;
50				t.serialize_field("data", p)?;
51				t.end()
52			}
53			FooterChild::Table(ref c) => {
54				let mut t = serializer.serialize_struct("Table", 2)?;
55				t.serialize_field("type", "table")?;
56				t.serialize_field("data", c)?;
57				t.end()
58			}
59		}
60	}
61}