docx_reader/documents/elements/
numbering_property.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
54
55
56
57
use serde::ser::{SerializeStruct, Serializer};
use serde::Serialize;

use super::{IndentLevel, NumberingId};

#[derive(Debug, Clone, PartialEq)]
pub struct NumberingProperty {
	pub id: Option<NumberingId>,
	pub level: Option<IndentLevel>,
}

impl Default for NumberingProperty {
	fn default() -> Self {
		NumberingProperty {
			id: None,
			level: None,
		}
	}
}

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

	pub fn id(mut self, id: NumberingId) -> NumberingProperty {
		self.id = Some(id);
		self
	}

	pub fn add_num(mut self, id: NumberingId, level: IndentLevel) -> NumberingProperty {
		self.id = Some(id);
		self.level = Some(level);
		self
	}
}

impl Serialize for NumberingProperty {
	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
	where
		S: Serializer,
	{
		let mut t = serializer.serialize_struct("NumberProperty", 2)?;
		let mut id: Option<usize> = None;
		if let Some(n) = &self.id {
			id = Some(n.id);
		}
		t.serialize_field("id", &id)?;

		let mut level: Option<usize> = None;
		if let Some(n) = &self.level {
			level = Some(n.val);
		}
		t.serialize_field("level", &level)?;
		t.end()
	}
}