eggress_pproxy_compat/
warnings.rs1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq)]
5pub struct CompatWarning {
6 pub category: &'static str,
8 pub message: String,
10}
11
12impl fmt::Display for CompatWarning {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 write!(f, "[{}] {}", self.category, self.message)
15 }
16}
17
18#[derive(Debug, Clone, PartialEq)]
20pub struct UnsupportedFeature {
21 pub feature: &'static str,
23 pub detail: String,
25}
26
27impl fmt::Display for UnsupportedFeature {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 write!(f, "unsupported {}: {}", self.feature, self.detail)
30 }
31}
32
33#[derive(Debug, Clone)]
35pub struct TranslationOutput {
36 pub toml: String,
38 pub warnings: Vec<CompatWarning>,
40 pub unsupported: Vec<UnsupportedFeature>,
42}
43
44impl TranslationOutput {
45 pub fn new(toml: String) -> Self {
46 Self {
47 toml,
48 warnings: Vec::new(),
49 unsupported: Vec::new(),
50 }
51 }
52
53 pub fn with_warning(mut self, category: &'static str, message: impl Into<String>) -> Self {
54 self.warnings.push(CompatWarning {
55 category,
56 message: message.into(),
57 });
58 self
59 }
60
61 pub fn with_unsupported(mut self, feature: &'static str, detail: impl Into<String>) -> Self {
62 self.unsupported.push(UnsupportedFeature {
63 feature,
64 detail: detail.into(),
65 });
66 self
67 }
68
69 pub fn with_warnings(mut self, warnings: Vec<CompatWarning>) -> Self {
70 self.warnings.extend(warnings);
71 self
72 }
73
74 pub fn with_unsupported_features(mut self, features: Vec<UnsupportedFeature>) -> Self {
75 self.unsupported.extend(features);
76 self
77 }
78
79 pub fn has_unsupported(&self) -> bool {
80 !self.unsupported.is_empty()
81 }
82
83 pub fn warnings_to_string(&self) -> String {
84 let mut out = String::new();
85 for w in &self.warnings {
86 out.push_str(&format!("{w}\n"));
87 }
88 for u in &self.unsupported {
89 out.push_str(&format!("{u}\n"));
90 }
91 out
92 }
93}