provenant/output_schema/
tallies.rs1use serde::{Deserialize, Serialize};
5
6use super::tally_entry::OutputTallyEntry;
7
8#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
9pub struct OutputTallies {
10 #[serde(default, skip_serializing_if = "Vec::is_empty")]
11 pub detected_license_expression: Vec<OutputTallyEntry>,
12 #[serde(default, skip_serializing_if = "Vec::is_empty")]
13 pub copyrights: Vec<OutputTallyEntry>,
14 #[serde(default, skip_serializing_if = "Vec::is_empty")]
15 pub holders: Vec<OutputTallyEntry>,
16 #[serde(default, skip_serializing_if = "Vec::is_empty")]
17 pub authors: Vec<OutputTallyEntry>,
18 #[serde(default, skip_serializing_if = "Vec::is_empty")]
19 pub programming_language: Vec<OutputTallyEntry>,
20}
21
22impl From<&crate::models::Tallies> for OutputTallies {
23 fn from(value: &crate::models::Tallies) -> Self {
24 Self {
25 detected_license_expression: value
26 .detected_license_expression
27 .iter()
28 .map(OutputTallyEntry::from)
29 .collect(),
30 copyrights: value
31 .copyrights
32 .iter()
33 .map(OutputTallyEntry::from)
34 .collect(),
35 holders: value.holders.iter().map(OutputTallyEntry::from).collect(),
36 authors: value.authors.iter().map(OutputTallyEntry::from).collect(),
37 programming_language: value
38 .programming_language
39 .iter()
40 .map(OutputTallyEntry::from)
41 .collect(),
42 }
43 }
44}
45
46impl TryFrom<&OutputTallies> for crate::models::Tallies {
47 type Error = String;
48 fn try_from(value: &OutputTallies) -> Result<Self, Self::Error> {
49 let mut detected_license_expression =
50 Vec::with_capacity(value.detected_license_expression.len());
51 for e in &value.detected_license_expression {
52 detected_license_expression.push(crate::models::TallyEntry::from(e));
53 }
54 let mut copyrights = Vec::with_capacity(value.copyrights.len());
55 for e in &value.copyrights {
56 copyrights.push(crate::models::TallyEntry::from(e));
57 }
58 let mut holders = Vec::with_capacity(value.holders.len());
59 for e in &value.holders {
60 holders.push(crate::models::TallyEntry::from(e));
61 }
62 let mut authors = Vec::with_capacity(value.authors.len());
63 for e in &value.authors {
64 authors.push(crate::models::TallyEntry::from(e));
65 }
66 let mut programming_language = Vec::with_capacity(value.programming_language.len());
67 for e in &value.programming_language {
68 programming_language.push(crate::models::TallyEntry::from(e));
69 }
70 Ok(Self {
71 detected_license_expression,
72 copyrights,
73 holders,
74 authors,
75 programming_language,
76 })
77 }
78}