docx_reader/documents/elements/
wps_shape.rs

1use super::*;
2use serde::ser::{SerializeStruct, Serializer};
3use serde::Serialize;
4
5#[derive(Debug, Clone, Serialize, PartialEq)]
6#[serde(rename_all = "camelCase")]
7pub struct WpsShape {
8	children: Vec<WpsShapeChild>,
9}
10
11#[derive(Debug, Clone, PartialEq)]
12pub enum WpsShapeChild {
13	WpsTextBox(WpsTextBox),
14}
15
16impl Serialize for WpsShapeChild {
17	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
18	where
19		S: Serializer,
20	{
21		match *self {
22			WpsShapeChild::WpsTextBox(ref s) => {
23				let mut t = serializer.serialize_struct("WpsTextBox", 2)?;
24				t.serialize_field("type", "textbox")?;
25				t.serialize_field("data", s)?;
26				t.end()
27			}
28		}
29	}
30}
31
32impl WpsShape {
33	pub fn new() -> WpsShape {
34		Default::default()
35	}
36
37	pub fn add_text_box(mut self, text_box: WpsTextBox) -> Self {
38		self.children.push(WpsShapeChild::WpsTextBox(text_box));
39		self
40	}
41}
42
43impl Default for WpsShape {
44	fn default() -> Self {
45		WpsShape { children: vec![] }
46	}
47}