json2pdf_client/protocol/
mod.rs

1use crate::protocol::document_settings::DocumentSettings;
2use serde::Serialize;
3use std::fmt::Debug;
4
5mod border;
6mod document_settings;
7mod elements;
8
9pub use border::*;
10pub use document_settings::*;
11pub use elements::*;
12
13/// The specification for the PDF document
14#[derive(Debug, Default, Clone, Serialize)]
15pub struct DocumentSpecification {
16    #[serde(skip_serializing_if = "Option::is_none")]
17    settings: Option<DocumentSettings>,
18    elements: Vec<Element>,
19}
20
21impl DocumentSpecification {
22    /// Create a new specification with no elements
23    pub fn new() -> Self {
24        Self::default()
25    }
26
27    /// Add an element to the document
28    pub fn add_element(mut self, element: Element) -> Self {
29        self.elements.push(element);
30        self
31    }
32
33    /// Set all elements for the document
34    pub fn set_elements(mut self, elements: Vec<Element>) -> Self {
35        self.elements = elements;
36        self
37    }
38
39    /// Set the document  settings
40    pub fn set_document_settings(mut self, document_settings: DocumentSettings) -> Self {
41        self.settings = Some(document_settings);
42        self
43    }
44}