trz_gateway_common/protos/
mod.rs1pub mod terrazzo {
6 pub mod remote {
7 pub mod health {
8 include!(concat!(env!("OUT_DIR"), "/terrazzo.remote.health.rs"));
9 }
10
11 #[cfg(debug_assertions)]
12 pub mod tests {
13 use std::fmt::Debug;
14 use std::fmt::Display;
15
16 include!(concat!(env!("OUT_DIR"), "/terrazzo.remote.tests.rs"));
17
18 impl From<i64> for Expression {
19 fn from(value: i64) -> Self {
20 Self {
21 kind: Some(expression::Kind::Value(value.into())),
22 }
23 }
24 }
25
26 impl From<f64> for Expression {
27 fn from(value: f64) -> Self {
28 Self {
29 kind: Some(expression::Kind::Value(value.into())),
30 }
31 }
32 }
33
34 impl From<i64> for Value {
35 fn from(value: i64) -> Self {
36 Self {
37 kind: Some(value::Kind::I(value)),
38 }
39 }
40 }
41
42 impl From<f64> for Value {
43 fn from(value: f64) -> Self {
44 Self {
45 kind: Some(value::Kind::F(value)),
46 }
47 }
48 }
49
50 impl std::ops::Add for Expression {
51 type Output = Expression;
52
53 fn add(self, rhs: Self) -> Self::Output {
54 Self::new(self, Operator::Plus, rhs)
55 }
56 }
57
58 impl std::ops::Sub for Expression {
59 type Output = Expression;
60
61 fn sub(self, rhs: Self) -> Self::Output {
62 Self::new(self, Operator::Minus, rhs)
63 }
64 }
65
66 impl std::ops::Mul for Expression {
67 type Output = Expression;
68
69 fn mul(self, rhs: Self) -> Self::Output {
70 Self::new(self, Operator::Multiply, rhs)
71 }
72 }
73
74 impl std::ops::Div for Expression {
75 type Output = Expression;
76
77 fn div(self, rhs: Self) -> Self::Output {
78 Self::new(self, Operator::Divide, rhs)
79 }
80 }
81
82 impl Expression {
83 pub fn new(left: Expression, operator: Operator, right: Expression) -> Self {
84 Self {
85 kind: Some(expression::Kind::Operation(Box::new(Operation {
86 left: Some(Box::new(left)),
87 operator: operator as i32,
88 right: Some(Box::new(right)),
89 }))),
90 }
91 }
92 }
93
94 impl Display for Expression {
95 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
96 let Expression { kind } = self;
97 let Some(kind) = kind else {
98 return Display::fmt("NULL", f);
99 };
100 match kind {
101 expression::Kind::Operation(operation) => Display::fmt(operation, f),
102 expression::Kind::Value(value) => Display::fmt(value, f),
103 }
104 }
105 }
106
107 impl Display for Value {
108 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
109 let Value { kind } = self;
110 let Some(kind) = kind else {
111 return Display::fmt("NULL", f);
112 };
113 match kind {
114 value::Kind::I(v) => Display::fmt(v, f),
115 value::Kind::F(v) => Display::fmt(v, f),
116 }
117 }
118 }
119
120 impl Display for Operation {
121 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
122 match &self.left {
123 Some(left) => Display::fmt(left, f)?,
124 None => Display::fmt("NULL", f)?,
125 }
126 Display::fmt(&self.operator(), f)?;
127 match &self.right {
128 Some(right) => Display::fmt(right, f)?,
129 None => Display::fmt("NULL", f)?,
130 }
131 Ok(())
132 }
133 }
134
135 impl Display for Operator {
136 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
137 let str = match self {
138 Operator::UndefinedOperand => " UNDEFINED ",
139 Operator::Plus => " + ",
140 Operator::Minus => " - ",
141 Operator::Multiply => " * ",
142 Operator::Divide => " / ",
143 };
144 Display::fmt(str, f)
145 }
146 }
147 }
148 }
149}