easyofd_core/doc/permission/
print.rs1#[derive(Debug, Clone)]
7pub struct Print {
8 pub printable: bool,
10 pub copies: Option<u32>,
12}
13
14impl Print {
15 #[must_use]
17 pub fn new() -> Self {
18 Self {
19 printable: true,
20 copies: None,
21 }
22 }
23
24 #[must_use]
26 pub fn disabled() -> Self {
27 Self {
28 printable: false,
29 copies: None,
30 }
31 }
32
33 #[must_use]
35 pub fn with_copies(mut self, copies: u32) -> Self {
36 self.copies = Some(copies);
37 self
38 }
39
40 #[must_use]
42 pub fn to_xml_string(&self) -> String {
43 let copies_attr = match self.copies {
44 Some(c) => format!(" Copies=\"{c}\""),
45 None => String::new(),
46 };
47 format!("<Print Printable=\"{}\"{copies_attr}/>", self.printable)
48 }
49}
50
51impl Default for Print {
52 fn default() -> Self {
53 Self::new()
54 }
55}
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_print_new() {
63 let p = Print::new();
64 assert!(p.printable);
65 assert!(p.copies.is_none());
66 let p2 = Print::default();
67 assert!(p2.printable);
68 }
69
70 #[test]
71 fn test_print_disabled_and_xml() {
72 let p = Print::disabled();
73 let xml = p.to_xml_string();
74 assert!(xml.contains("Printable=\"false\""));
75
76 let p3 = Print::new().with_copies(3);
77 let xml3 = p3.to_xml_string();
78 assert!(xml3.contains("Copies=\"3\""));
79 assert!(xml3.contains("Printable=\"true\""));
80 }
81}