docx_rs/documents/doc_props/
mod.rs

1mod app;
2mod core;
3mod custom;
4
5pub use self::app::*;
6pub use self::core::*;
7pub use self::custom::*;
8
9use crate::documents::BuildXML;
10
11use serde::Serialize;
12
13#[derive(Debug, Clone, PartialEq, Serialize)]
14#[serde(rename_all = "camelCase")]
15pub struct DocProps {
16    pub app: AppProps,
17    pub core: CoreProps,
18    pub custom: CustomProps,
19}
20
21impl DocProps {
22    pub(crate) fn new(core_config: CorePropsConfig) -> DocProps {
23        let app = AppProps::new();
24        let core = CoreProps::new(core_config);
25        let custom = CustomProps::new();
26        DocProps { app, core, custom }
27    }
28
29    pub fn created_at(mut self, date: &str) -> Self {
30        self.core = self.core.created_at(date);
31        self
32    }
33
34    pub fn updated_at(mut self, date: &str) -> Self {
35        self.core = self.core.updated_at(date);
36        self
37    }
38
39    pub fn custom_property(mut self, name: impl Into<String>, item: impl Into<String>) -> Self {
40        self.custom = self.custom.add_custom_property(name.into(), item.into());
41        self
42    }
43
44    pub(crate) fn build(&self) -> XMLDocProps {
45        XMLDocProps {
46            app: self.app.build(),
47            core: self.core.build(),
48            custom: self.custom.build(),
49        }
50    }
51}
52
53#[derive(Debug)]
54pub struct XMLDocProps {
55    pub app: Vec<u8>,
56    pub core: Vec<u8>,
57    pub custom: Vec<u8>,
58}