json2pdf_client/protocol/elements/
mod.rs1use crate::protocol::border::BorderSettings;
2use serde::Serialize;
3
4mod image;
5mod paragraph;
6mod table;
7
8pub use image::*;
9pub use paragraph::*;
10pub use table::*;
11
12#[derive(Debug, Clone, Serialize)]
13#[serde(untagged)]
14enum ElementData {
15 Image(Image),
16 Paragraph(Paragraph),
17 Table(Table),
18}
19
20#[derive(Debug, Clone, Serialize)]
21enum ElementType {
22 Image,
23 Paragraph,
24 Table,
25}
26
27#[derive(Debug, Clone, Serialize)]
28pub struct Element {
29 #[serde(flatten)]
30 data: ElementData,
31 #[serde(skip_serializing_if = "Option::is_none")]
32 #[serde(rename = "borderSettings")]
33 border_settings: Option<BorderSettings>,
34 #[serde(rename = "type")]
35 content_type: ElementType,
36}
37
38impl Element {
39 pub fn image(image: Image) -> Self {
41 Self {
42 content_type: ElementType::Image,
43 data: ElementData::Image(image),
44 border_settings: None,
45 }
46 }
47
48 pub fn table(table: Table) -> Self {
50 Self {
51 content_type: ElementType::Table,
52 data: ElementData::Table(table),
53 border_settings: None,
54 }
55 }
56
57 pub fn paragraph(paragraph: Paragraph) -> Self {
59 Self {
60 content_type: ElementType::Paragraph,
61 data: ElementData::Paragraph(paragraph),
62 border_settings: None,
63 }
64 }
65
66 pub fn border(mut self, border: BorderSettings) -> Self {
68 self.border_settings = Some(border);
69 self
70 }
71}