1use core::fmt;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
23#[non_exhaustive]
24pub enum Kind {
25 #[default]
27 Plain,
28 AbsoluteTemperature,
30 TemperatureDifference,
32 GaugePressure,
35 NormalVolume,
37 StandardVolume,
39}
40
41impl Kind {
42 #[must_use]
46 pub const fn is_reference(self) -> bool {
47 matches!(
48 self,
49 Self::GaugePressure | Self::NormalVolume | Self::StandardVolume
50 )
51 }
52
53 #[must_use]
55 pub const fn name(self) -> &'static str {
56 match self {
57 Self::Plain => "plain",
58 Self::AbsoluteTemperature => "absolute_temperature",
59 Self::TemperatureDifference => "temperature_difference",
60 Self::GaugePressure => "gauge_pressure",
61 Self::NormalVolume => "normal_volume",
62 Self::StandardVolume => "standard_volume",
63 }
64 }
65
66 #[must_use]
68 pub fn from_name(name: &str) -> Option<Self> {
69 match name {
70 "plain" => Some(Self::Plain),
71 "absolute_temperature" => Some(Self::AbsoluteTemperature),
72 "temperature_difference" => Some(Self::TemperatureDifference),
73 "gauge_pressure" => Some(Self::GaugePressure),
74 "normal_volume" => Some(Self::NormalVolume),
75 "standard_volume" => Some(Self::StandardVolume),
76 _ => None,
77 }
78 }
79}
80
81impl fmt::Display for Kind {
82 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
83 f.write_str(self.name())
84 }
85}
86
87#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
92#[non_exhaustive]
93pub enum Shape {
94 Linear,
96 Affine,
98}
99
100impl Shape {
101 #[must_use]
103 pub const fn name(self) -> &'static str {
104 match self {
105 Self::Linear => "linear",
106 Self::Affine => "affine",
107 }
108 }
109
110 #[must_use]
112 pub fn from_name(name: &str) -> Option<Self> {
113 match name {
114 "linear" => Some(Self::Linear),
115 "affine" => Some(Self::Affine),
116 _ => None,
117 }
118 }
119}
120
121impl fmt::Display for Shape {
122 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
123 f.write_str(self.name())
124 }
125}
126
127#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
129#[non_exhaustive]
130pub enum Exactness {
131 Defined,
133 Measured,
135}
136
137impl Exactness {
138 #[must_use]
140 pub const fn name(self) -> &'static str {
141 match self {
142 Self::Defined => "defined",
143 Self::Measured => "measured",
144 }
145 }
146
147 #[must_use]
149 pub fn from_name(name: &str) -> Option<Self> {
150 match name {
151 "defined" => Some(Self::Defined),
152 "measured" => Some(Self::Measured),
153 _ => None,
154 }
155 }
156
157 #[must_use]
159 pub const fn combine(self, other: Self) -> Self {
160 match (self, other) {
161 (Self::Defined, Self::Defined) => Self::Defined,
162 _ => Self::Measured,
163 }
164 }
165}
166
167impl fmt::Display for Exactness {
168 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
169 f.write_str(self.name())
170 }
171}
172
173#[cfg(test)]
174mod tests {
175 use super::*;
176
177 const ALL: [Kind; 6] = [
178 Kind::Plain,
179 Kind::AbsoluteTemperature,
180 Kind::TemperatureDifference,
181 Kind::GaugePressure,
182 Kind::NormalVolume,
183 Kind::StandardVolume,
184 ];
185
186 #[test]
187 fn names_round_trip() {
188 for k in ALL {
189 assert_eq!(Kind::from_name(k.name()), Some(k));
190 }
191 assert_eq!(Kind::from_name("nope"), None);
192 assert_eq!(Shape::from_name("affine"), Some(Shape::Affine));
193 assert_eq!(Exactness::from_name("measured"), Some(Exactness::Measured));
194 }
195
196 #[test]
197 fn exactness_combine() {
198 assert_eq!(
199 Exactness::Defined.combine(Exactness::Defined),
200 Exactness::Defined
201 );
202 assert_eq!(
203 Exactness::Defined.combine(Exactness::Measured),
204 Exactness::Measured
205 );
206 }
207}