Procházet zdrojové kódy

rust-protocol: Add functions to convert between Value and (ValueType, i64).

Mathias Gottschlag před 5 roky
rodič
revize
ea8a5e0b04
1 změnil soubory, kde provedl 19 přidání a 0 odebrání
  1. 19
    0
      common/rust-protocol/src/lib.rs

+ 19
- 0
common/rust-protocol/src/lib.rs Zobrazit soubor

@@ -231,6 +231,25 @@ impl Value {
231 231
             Self::Humidity(_) => 3,
232 232
         }
233 233
     }
234
+
235
+    pub fn split(&self) -> Option<(ValueType, i64)> {
236
+        match self {
237
+            Self::Invalid => None,
238
+            Self::Time(t) => Some((ValueType::Time, *t as i64)),
239
+            Self::Temperature(t) => Some((ValueType::Temperature, *t as i64)),
240
+            Self::Pressure(p) => Some((ValueType::Pressure, *p as i64)),
241
+            Self::Humidity(h) => Some((ValueType::Humidity, *h as i64)),
242
+        }
243
+    }
244
+
245
+    pub fn combine(type_: ValueType, value: i64) -> Value {
246
+        match type_ {
247
+            ValueType::Time => Self::Time(value as u64),
248
+            ValueType::Temperature => Self::Temperature(value as i16),
249
+            ValueType::Pressure => Self::Pressure(value as u32),
250
+            ValueType::Humidity => Self::Humidity(value as u16),
251
+        }
252
+    }
234 253
 }
235 254
 
236 255
 #[derive(Debug, Clone, Copy, PartialEq)]

Loading…
Zrušit
Uložit