easydoc_core/metadata/
document.rs1#[derive(Debug, Clone, Default, PartialEq, Eq)]
6pub struct DocumentMeta {
7 pub title: Option<String>,
9 pub author: Option<String>,
11 pub subject: Option<String>,
13 pub keywords: Option<String>,
15 pub page_width: Option<u32>,
17 pub page_height: Option<u32>,
19 pub landscape: bool,
21}
22
23impl DocumentMeta {
24 #[must_use]
26 pub fn new() -> Self {
27 Self::default()
28 }
29
30 #[must_use]
32 pub fn title(mut self, title: impl Into<String>) -> Self {
33 self.title = Some(title.into());
34 self
35 }
36
37 #[must_use]
39 pub fn author(mut self, author: impl Into<String>) -> Self {
40 self.author = Some(author.into());
41 self
42 }
43
44 #[must_use]
46 pub fn subject(mut self, subject: impl Into<String>) -> Self {
47 self.subject = Some(subject.into());
48 self
49 }
50
51 #[must_use]
53 pub fn keywords(mut self, keywords: impl Into<String>) -> Self {
54 self.keywords = Some(keywords.into());
55 self
56 }
57
58 #[must_use]
60 pub fn landscape(mut self, landscape: bool) -> Self {
61 self.landscape = landscape;
62 self
63 }
64}
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69
70 #[test]
71 fn document_meta_builder_chain() {
72 let meta = DocumentMeta::new()
73 .title("Test Document")
74 .author("Author Name")
75 .subject("Test Subject")
76 .keywords("rust,docx")
77 .landscape(true);
78 assert_eq!(meta.title.as_deref(), Some("Test Document"));
79 assert_eq!(meta.author.as_deref(), Some("Author Name"));
80 assert_eq!(meta.subject.as_deref(), Some("Test Subject"));
81 assert_eq!(meta.keywords.as_deref(), Some("rust,docx"));
82 assert!(meta.landscape);
83 }
84
85 #[test]
86 fn document_meta_default() {
87 let meta = DocumentMeta::default();
88 assert!(meta.title.is_none());
89 assert!(meta.author.is_none());
90 assert!(meta.subject.is_none());
91 assert!(meta.keywords.is_none());
92 assert!(meta.page_width.is_none());
93 assert!(meta.page_height.is_none());
94 assert!(!meta.landscape);
95 }
96
97 #[test]
98 fn document_meta_clone_eq() {
99 let meta = DocumentMeta::new().title("Test");
100 let meta2 = meta.clone();
101 assert_eq!(meta, meta2);
102 }
103
104 #[test]
105 fn document_meta_debug() {
106 let meta = DocumentMeta::new().title("Test");
107 let dbg = format!("{meta:?}");
108 assert!(dbg.contains("Test"));
109 }
110
111 #[test]
112 fn document_meta_page_dimensions() {
113 let mut meta = DocumentMeta::new();
114 meta.page_width = Some(11906);
115 meta.page_height = Some(16838);
116 assert_eq!(meta.page_width, Some(11906));
117 assert_eq!(meta.page_height, Some(16838));
118 }
119}