docx_reader/documents/elements/
wps_shape.rs

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
use super::*;
use serde::ser::{SerializeStruct, Serializer};
use serde::Serialize;

#[derive(Debug, Clone, Serialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct WpsShape {
	children: Vec<WpsShapeChild>,
}

#[derive(Debug, Clone, PartialEq)]
pub enum WpsShapeChild {
	WpsTextBox(WpsTextBox),
}

impl Serialize for WpsShapeChild {
	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
	where
		S: Serializer,
	{
		match *self {
			WpsShapeChild::WpsTextBox(ref s) => {
				let mut t = serializer.serialize_struct("WpsTextBox", 2)?;
				t.serialize_field("type", "textbox")?;
				t.serialize_field("data", s)?;
				t.end()
			}
		}
	}
}

impl WpsShape {
	pub fn new() -> WpsShape {
		Default::default()
	}

	pub fn add_text_box(mut self, text_box: WpsTextBox) -> Self {
		self.children.push(WpsShapeChild::WpsTextBox(text_box));
		self
	}
}

impl Default for WpsShape {
	fn default() -> Self {
		WpsShape { children: vec![] }
	}
}