docx_reader/documents/elements/
drawing.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
48
49
50
51
52
use super::*;
use serde::{ser::*, Serialize};

#[derive(Debug, Clone, PartialEq, Default, Serialize)]
pub struct Drawing {
	#[serde(flatten)]
	pub data: Option<DrawingData>,
}

#[derive(Debug, Clone, PartialEq)]
pub enum DrawingData {
	Pic(Pic),
	TextBox(TextBox),
}

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

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

	pub fn pic(mut self, pic: Pic) -> Drawing {
		self.data = Some(DrawingData::Pic(pic));
		self
	}

	pub fn text_box(mut self, t: TextBox) -> Drawing {
		self.data = Some(DrawingData::TextBox(t));
		self
	}
}