docx_reader/documents/elements/
instr_text.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
53
use serde::ser::{SerializeStruct, Serializer};
use serde::Serialize;

use crate::documents::*;

#[derive(Debug, Clone, PartialEq)]
pub enum InstrText {
	TOC(InstrToC),
	TC(InstrTC),
	PAGEREF(InstrPAGEREF),
	HYPERLINK(InstrHyperlink),
	Unsupported(String),
}

impl Serialize for InstrText {
	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
	where
		S: Serializer,
	{
		match *self {
			InstrText::TOC(ref s) => {
				let mut t = serializer.serialize_struct("TOC", 2)?;
				t.serialize_field("type", "toc")?;
				t.serialize_field("data", s)?;
				t.end()
			}
			InstrText::TC(ref s) => {
				let mut t = serializer.serialize_struct("TC", 2)?;
				t.serialize_field("type", "tc")?;
				t.serialize_field("data", s)?;
				t.end()
			}
			InstrText::PAGEREF(ref s) => {
				let mut t = serializer.serialize_struct("PAGEREF", 2)?;
				t.serialize_field("type", "pageref")?;
				t.serialize_field("data", s)?;
				t.end()
			}
			InstrText::HYPERLINK(ref s) => {
				let mut t = serializer.serialize_struct("HYPERLINK", 2)?;
				t.serialize_field("type", "hyperlink")?;
				t.serialize_field("data", s)?;
				t.end()
			}
			InstrText::Unsupported(ref s) => {
				let mut t = serializer.serialize_struct("Unsupported", 2)?;
				t.serialize_field("type", "unsupported")?;
				t.serialize_field("data", s)?;
				t.end()
			}
		}
	}
}