docx_rs/documents/
custom_item_rels.rs1use serde::Serialize;
2use std::io::Write;
3
4use crate::documents::BuildXML;
5use crate::xml_builder::*;
6
7#[derive(Debug, Clone, PartialEq, Serialize, Default)]
8#[serde(rename_all = "camelCase")]
9pub struct CustomItemRels {
10 custom_item_count: usize,
11}
12
13impl CustomItemRels {
14 pub fn new() -> CustomItemRels {
15 Default::default()
16 }
17
18 pub fn add_item(mut self) -> Self {
19 self.custom_item_count += 1;
20 self
21 }
22}
23
24impl BuildXML for CustomItemRels {
25 fn build_to<W: Write>(
26 &self,
27 stream: xml::writer::EventWriter<W>,
28 ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
29 XMLBuilder::from(stream)
30 .declaration(Some(true))?
31 .open_relationships("http://schemas.openxmlformats.org/package/2006/relationships")?
32 .apply_each(0..self.custom_item_count, |id, b| {
33 b.relationship(
34 &format!("rId{}", id + 1),
35 "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXmlProps",
36 &format!("itemProps{}.xml", id + 1),
37 )
38 })?
39 .close()?
40 .into_inner()
41 }
42}