Skip to main content

paperforge_core/
metadata.rs

1use std::collections::HashMap;
2
3/// Document metadata.
4#[derive(Debug, Clone, Default)]
5pub struct Metadata {
6    inner: HashMap<String, String>,
7}
8
9impl Metadata {
10    pub fn new() -> Self {
11        Self::default()
12    }
13
14    pub fn title(&self) -> Option<&str> {
15        self.inner.get("title").map(|s| s.as_str())
16    }
17
18    pub fn set_title(&mut self, value: &str) -> &mut Self {
19        self.inner.insert("title".to_string(), value.to_string());
20        self
21    }
22
23    pub fn author(&self) -> Option<&str> {
24        self.inner.get("author").map(|s| s.as_str())
25    }
26
27    pub fn set_author(&mut self, value: &str) -> &mut Self {
28        self.inner.insert("author".to_string(), value.to_string());
29        self
30    }
31
32    pub fn subject(&self) -> Option<&str> {
33        self.inner.get("subject").map(|s| s.as_str())
34    }
35
36    pub fn set_subject(&mut self, value: &str) -> &mut Self {
37        self.inner.insert("subject".to_string(), value.to_string());
38        self
39    }
40
41    pub fn keywords(&self) -> Option<&str> {
42        self.inner.get("keywords").map(|s| s.as_str())
43    }
44
45    pub fn set_keywords(&mut self, value: &str) -> &mut Self {
46        self.inner.insert("keywords".to_string(), value.to_string());
47        self
48    }
49
50    pub fn creator(&self) -> Option<&str> {
51        self.inner.get("creator").map(|s| s.as_str())
52    }
53
54    pub fn set_creator(&mut self, value: &str) -> &mut Self {
55        self.inner.insert("creator".to_string(), value.to_string());
56        self
57    }
58
59    pub fn producer(&self) -> Option<&str> {
60        self.inner.get("producer").map(|s| s.as_str())
61    }
62
63    pub fn set_producer(&mut self, value: &str) -> &mut Self {
64        self.inner.insert("producer".to_string(), value.to_string());
65        self
66    }
67
68    pub fn insert(&mut self, key: &str, value: &str) -> &mut Self {
69        self.inner.insert(key.to_string(), value.to_string());
70        self
71    }
72
73    pub fn get(&self, key: &str) -> Option<&str> {
74        self.inner.get(key).map(|s| s.as_str())
75    }
76
77    pub fn iter(&self) -> impl Iterator<Item = (&str, &str)> {
78        self.inner.iter().map(|(k, v)| (k.as_str(), v.as_str()))
79    }
80}