plantuml_server_client_rs/metadata/
plantuml.rs

1use derive_getters::Getters;
2use serde::{Deserialize, Serialize};
3use std::path::PathBuf;
4use typed_builder::TypedBuilder;
5
6/// Information in the generated PlantUML diagrams
7#[derive(Deserialize, Serialize, Clone, Debug)]
8pub struct PlantUmlMetadata(Vec<PlantUmlMetadataItem>);
9
10/// Information in the generated PlantUML diagram
11///
12/// * `index` - The index of the order of the diagrams in the file
13/// * `id` - The id of the diagram
14/// * `output_path` - The path of output file
15/// * `combined_output_path` - The path of `combined` PlantUML content's output file
16/// * `title` - The last title in the PlantUML content
17/// * `titles` - The titles in the PlantUML content
18/// * `header` - The last header in the PlantUML content
19/// * `headers` - The headers in the PlantUML content
20/// * `footer` - The last footer in the PlantUML content
21/// * `footers` - The footers in the PlantUML content
22#[derive(Deserialize, Serialize, TypedBuilder, Getters, Clone, Debug)]
23#[builder(mutators(
24    pub fn titles(&mut self, titles: Vec<String>){
25        self.title = titles.last().cloned();
26        self.titles = titles;
27    }
28
29    pub fn headers(&mut self, headers: Vec<String>){
30        self.header = headers.last().cloned();
31        self.headers = headers;
32    }
33
34    pub fn footers(&mut self, footers: Vec<String>){
35        self.footer = footers.last().cloned();
36        self.footers = footers;
37    }
38))]
39pub struct PlantUmlMetadataItem {
40    index: usize,
41    #[serde(skip_serializing_if = "Option::is_none")]
42    id: Option<String>,
43
44    output_path: PathBuf,
45    #[serde(skip_serializing_if = "Option::is_none")]
46    #[builder(default)]
47    combined_output_path: Option<PathBuf>,
48
49    #[serde(skip_serializing_if = "Option::is_none")]
50    #[builder(via_mutators(init = None))]
51    title: Option<String>,
52    #[builder(via_mutators(init = Vec::new()))]
53    titles: Vec<String>,
54
55    #[serde(skip_serializing_if = "Option::is_none")]
56    #[builder(via_mutators(init = None))]
57    header: Option<String>,
58    #[builder(via_mutators(init = Vec::new()))]
59    headers: Vec<String>,
60
61    #[serde(skip_serializing_if = "Option::is_none")]
62    #[builder(via_mutators(init = None))]
63    footer: Option<String>,
64    #[builder(via_mutators(init = Vec::new()))]
65    footers: Vec<String>,
66}
67
68impl PlantUmlMetadata {
69    /// Returns a reference to an item of index.
70    pub fn get(&self, index: usize) -> Option<&PlantUmlMetadataItem> {
71        self.0.get(index)
72    }
73
74    /// Returns `true` if the metadata has a length of 0.
75    pub fn is_empty(&self) -> bool {
76        self.0.is_empty()
77    }
78
79    /// Returns the number of elements in the metadata.
80    pub fn len(&self) -> usize {
81        self.0.len()
82    }
83
84    /// Returns an iterator over the metadata item.
85    pub fn iter(&self) -> impl std::iter::Iterator<Item = &PlantUmlMetadataItem> {
86        self.0.iter()
87    }
88}
89
90impl From<Vec<PlantUmlMetadataItem>> for PlantUmlMetadata {
91    fn from(inner: Vec<PlantUmlMetadataItem>) -> Self {
92        Self(inner)
93    }
94}
95
96impl PlantUmlMetadataItem {
97    /// An identifier of the diagram
98    pub fn identifier(&self) -> String {
99        self.id.clone().unwrap_or_else(|| self.index.to_string())
100    }
101}