Skip to main content

katana_document_viewer/
export_contract.rs

1use serde::{Deserialize, Serialize};
2
3use crate::export_contract_entries::{ENTRIES, EntrySeed};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
6pub enum HtmlExportReadiness {
7    Implemented,
8    RequiresKmmDto,
9    RequiresKdvImplementation,
10    RequiresKrrRender,
11    ExternalBackendRequired,
12}
13
14#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
15pub struct HtmlExportContractEntry {
16    pub feature: String,
17    pub notation: String,
18    pub current_state: String,
19    pub readiness: HtmlExportReadiness,
20}
21
22#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
23pub struct HtmlExportContractMatrix {
24    pub entries: Vec<HtmlExportContractEntry>,
25}
26
27impl HtmlExportContractMatrix {
28    pub fn v0_1() -> Self {
29        Self {
30            entries: ENTRIES.iter().map(Self::entry).collect(),
31        }
32    }
33
34    pub fn incomplete_entries(&self) -> Vec<&HtmlExportContractEntry> {
35        self.entries
36            .iter()
37            .filter(|entry| entry.readiness != HtmlExportReadiness::Implemented)
38            .collect()
39    }
40
41    pub fn kdv_owned_incomplete_entries(&self) -> Vec<&HtmlExportContractEntry> {
42        self.entries
43            .iter()
44            .filter(|entry| entry.readiness == HtmlExportReadiness::RequiresKdvImplementation)
45            .collect()
46    }
47
48    pub fn is_complete(&self) -> bool {
49        self.incomplete_entries().is_empty()
50    }
51
52    pub fn is_kdv_owned_complete(&self) -> bool {
53        self.kdv_owned_incomplete_entries().is_empty()
54    }
55
56    pub fn contains_feature(&self, feature: &str, readiness: HtmlExportReadiness) -> bool {
57        self.entries
58            .iter()
59            .any(|entry| entry.feature == feature && entry.readiness == readiness)
60    }
61
62    fn entry(seed: &EntrySeed) -> HtmlExportContractEntry {
63        let (feature, notation, current_state, readiness) = *seed;
64        HtmlExportContractEntry {
65            feature: feature.to_string(),
66            notation: notation.to_string(),
67            current_state: current_state.to_string(),
68            readiness,
69        }
70    }
71}
72
73#[cfg(test)]
74#[path = "export_contract_tests.rs"]
75mod tests;