1#[derive(Debug, Copy, Clone, PartialEq, Eq)]
11#[non_exhaustive]
12pub enum MeasurementUnit {
13 AccelG,
15 Ampere,
17 Becquerel,
19 Bool,
21 Candela,
23 Celsius,
25 Coulomb,
27 Decibel,
29 DecimalDegree,
31 Degree,
33 DegreePerSecond,
35 Farad,
37 Gram,
40 Gray,
42 Henry,
44 Hertz,
46 Joule,
48 Katal,
50 Kelvin,
52 Lumen,
54 Lux,
56 Meter,
58 MeterPerSecond,
60 Mole,
62 Newton,
64 Ohm,
66 PartsPerMillion,
68 Pascal,
70 Percent,
72 PercentageRelativeHumidity,
74 Radian,
76 Second,
78 Siemens,
80 Sievert,
82 Steradian,
84 Tesla,
86 Volt,
88 Watt,
90 Weber,
92}
93
94macro_rules! provide_unit_fmt {
95 ($unit:expr, $f:expr) => {
96 match $unit {
97 Self::AccelG => write!($f, "g"),
98 Self::Ampere => write!($f, "A"),
99 Self::Becquerel => write!($f, "Bq"),
100 Self::Bool => write!($f, ""),
101 Self::Candela => write!($f, "cd"),
102 Self::Celsius => write!($f, "°C"),
104 Self::Coulomb => write!($f, "C"),
105 Self::Decibel => write!($f, "dB"),
106 Self::DecimalDegree => write!($f, "°"),
107 Self::Degree => write!($f, "°"),
108 Self::DegreePerSecond => write!($f, "°/s"),
109 Self::Farad => write!($f, "F"),
110 Self::Gram => write!($f, "g"),
111 Self::Gray => write!($f, "Gy"),
112 Self::Henry => write!($f, "H"),
113 Self::Hertz => write!($f, "Hz"),
114 Self::Joule => write!($f, "J"),
115 Self::Katal => write!($f, "kat"),
116 Self::Kelvin => write!($f, "K"),
117 Self::Lumen => write!($f, "lm"),
118 Self::Lux => write!($f, "lx"),
119 Self::Meter => write!($f, "m"),
120 Self::MeterPerSecond => write!($f, "m/s"),
121 Self::Mole => write!($f, "mol"),
122 Self::Newton => write!($f, "N"),
123 Self::Ohm => write!($f, "Ω"),
124 Self::PartsPerMillion => write!($f, "ppm"),
125 Self::Pascal => write!($f, "Pa"),
126 Self::Percent => write!($f, "%"),
127 Self::PercentageRelativeHumidity => write!($f, "%RH"),
128 Self::Radian => write!($f, "rad"),
129 Self::Second => write!($f, "s"),
130 Self::Siemens => write!($f, "S"),
131 Self::Sievert => write!($f, "Sv"),
132 Self::Steradian => write!($f, "sr"),
133 Self::Tesla => write!($f, "T"),
134 Self::Volt => write!($f, "V"),
135 Self::Watt => write!($f, "W"),
136 Self::Weber => write!($f, "Wb"),
137 }
138 };
139}
140
141impl core::fmt::Display for MeasurementUnit {
142 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
143 provide_unit_fmt!(self, f)
144 }
145}
146
147#[cfg(feature = "defmt")]
148impl defmt::Format for MeasurementUnit {
149 fn format(&self, f: defmt::Formatter<'_>) {
150 use defmt::write;
151
152 provide_unit_fmt!(self, f);
153 }
154}