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}
33
34impl Kind {
35 #[must_use]
37 pub const fn name(self) -> &'static str {
38 match self {
39 Self::Plain => "plain",
40 Self::AbsoluteTemperature => "absolute_temperature",
41 Self::TemperatureDifference => "temperature_difference",
42 }
43 }
44
45 #[must_use]
47 pub fn from_name(name: &str) -> Option<Self> {
48 match name {
49 "plain" => Some(Self::Plain),
50 "absolute_temperature" => Some(Self::AbsoluteTemperature),
51 "temperature_difference" => Some(Self::TemperatureDifference),
52 _ => None,
53 }
54 }
55}
56
57impl fmt::Display for Kind {
58 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
59 f.write_str(self.name())
60 }
61}
62
63#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
68#[non_exhaustive]
69pub enum Shape {
70 Linear,
72 Affine,
74}
75
76impl Shape {
77 #[must_use]
79 pub const fn name(self) -> &'static str {
80 match self {
81 Self::Linear => "linear",
82 Self::Affine => "affine",
83 }
84 }
85
86 #[must_use]
88 pub fn from_name(name: &str) -> Option<Self> {
89 match name {
90 "linear" => Some(Self::Linear),
91 "affine" => Some(Self::Affine),
92 _ => None,
93 }
94 }
95}
96
97impl fmt::Display for Shape {
98 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
99 f.write_str(self.name())
100 }
101}
102
103#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
105#[non_exhaustive]
106pub enum Exactness {
107 Defined,
109 Measured,
111}
112
113impl Exactness {
114 #[must_use]
116 pub const fn name(self) -> &'static str {
117 match self {
118 Self::Defined => "defined",
119 Self::Measured => "measured",
120 }
121 }
122
123 #[must_use]
125 pub fn from_name(name: &str) -> Option<Self> {
126 match name {
127 "defined" => Some(Self::Defined),
128 "measured" => Some(Self::Measured),
129 _ => None,
130 }
131 }
132
133 #[must_use]
135 pub const fn combine(self, other: Self) -> Self {
136 match (self, other) {
137 (Self::Defined, Self::Defined) => Self::Defined,
138 _ => Self::Measured,
139 }
140 }
141}
142
143impl fmt::Display for Exactness {
144 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
145 f.write_str(self.name())
146 }
147}
148
149#[cfg(test)]
150mod tests {
151 use super::*;
152
153 const ALL: [Kind; 3] = [
154 Kind::Plain,
155 Kind::AbsoluteTemperature,
156 Kind::TemperatureDifference,
157 ];
158
159 #[test]
160 fn names_round_trip() {
161 for k in ALL {
162 assert_eq!(Kind::from_name(k.name()), Some(k));
163 }
164 assert_eq!(Kind::from_name("nope"), None);
165 assert_eq!(Shape::from_name("affine"), Some(Shape::Affine));
166 assert_eq!(Exactness::from_name("measured"), Some(Exactness::Measured));
167 }
168
169 #[test]
170 fn exactness_combine() {
171 assert_eq!(
172 Exactness::Defined.combine(Exactness::Defined),
173 Exactness::Defined
174 );
175 assert_eq!(
176 Exactness::Defined.combine(Exactness::Measured),
177 Exactness::Measured
178 );
179 }
180}