docx_reader/documents/
rels.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
4pub struct Rels {
5 pub rels: Vec<(String, String, String)>,
6}
7
8impl Rels {
9 pub fn new() -> Rels {
10 Default::default()
11 }
12
13 pub fn set_default(mut self) -> Self {
14 self.rels.push((
15 "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"
16 .to_owned(),
17 "rId1".to_owned(),
18 "docProps/core.xml".to_owned(),
19 ));
20 self.rels.push(
21 ("http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties".to_owned(),
22 "rId2".to_owned(), "docProps/app.xml".to_owned()),
23 );
24 self.rels.push((
25 "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
26 .to_owned(),
27 "rId3".to_owned(),
28 "word/document.xml".to_owned(),
29 ));
30 self.rels.push((
31 "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties"
32 .to_owned(),
33 "rId4".to_owned(),
34 "docProps/custom.xml".to_owned(),
35 ));
36 self
37 }
38
39 pub fn add_taskpanes_rel(mut self) -> Self {
40 self = self.add_rel(
41 "http://schemas.microsoft.com/office/2011/relationships/webextensiontaskpanes",
42 "word/webextensions/taskpanes.xml",
43 );
44 self
45 }
46
47 pub fn add_rel(mut self, rel_type: impl Into<String>, target: impl Into<String>) -> Self {
48 self.rels.push((
49 rel_type.into(),
50 format!("rId{}", self.rels.len() + 1),
51 target.into(),
52 ));
53 self
54 }
55
56 pub fn find_target(&self, rel_type: &str) -> Option<&(String, String, String)> {
57 self.rels.iter().find(|rel| rel.0 == rel_type)
58 }
59}
60
61impl Default for Rels {
62 fn default() -> Self {
63 Rels { rels: Vec::new() }
64 }
65}