docx_reader/documents/elements/
table_of_contents_item.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 serde::Serialize;

use crate::documents::*;

#[derive(Serialize, Debug, Clone, PartialEq, Default)]
pub struct TableOfContentsItem {
	pub instr: InstrToC,
	pub text: String,
	pub toc_key: String,
	pub level: usize,
	pub dirty: bool,
	pub page_ref: Option<String>,
}

impl TableOfContentsItem {
	pub fn new() -> Self {
		Self {
			level: 1,
			..Default::default()
		}
	}

	pub fn instr(mut self, instr: InstrToC) -> Self {
		self.instr = instr;
		self
	}

	pub fn text(mut self, text: impl Into<String>) -> Self {
		self.text = text.into();
		self
	}

	pub fn level(mut self, level: usize) -> Self {
		self.level = level;
		self
	}

	pub fn toc_key(mut self, key: impl Into<String>) -> Self {
		self.toc_key = key.into();
		self
	}

	pub fn page_ref(mut self, r: impl Into<String>) -> Self {
		self.page_ref = Some(r.into());
		self
	}
}