rsiot/components_config/influxdb3/
field_value.rs

1use std::fmt::Display;
2
3/// Значение в словаре `fields`
4#[derive(Clone, Debug)]
5pub struct FieldValue(String);
6
7impl From<bool> for FieldValue {
8    fn from(value: bool) -> Self {
9        FieldValue(value.to_string())
10    }
11}
12
13impl From<f32> for FieldValue {
14    fn from(value: f32) -> Self {
15        FieldValue(value.to_string())
16    }
17}
18
19impl From<f64> for FieldValue {
20    fn from(value: f64) -> Self {
21        FieldValue(value.to_string())
22    }
23}
24
25impl From<i8> for FieldValue {
26    fn from(value: i8) -> Self {
27        FieldValue(format!("{}i", value))
28    }
29}
30
31impl From<i16> for FieldValue {
32    fn from(value: i16) -> Self {
33        FieldValue(format!("{}i", value))
34    }
35}
36
37impl From<i32> for FieldValue {
38    fn from(value: i32) -> Self {
39        FieldValue(format!("{}i", value))
40    }
41}
42
43impl From<u8> for FieldValue {
44    fn from(value: u8) -> Self {
45        FieldValue(format!("{}u", value))
46    }
47}
48
49impl From<u16> for FieldValue {
50    fn from(value: u16) -> Self {
51        FieldValue(format!("{}u", value))
52    }
53}
54
55impl From<u32> for FieldValue {
56    fn from(value: u32) -> Self {
57        FieldValue(format!("{}u", value))
58    }
59}
60
61impl From<String> for FieldValue {
62    fn from(value: String) -> Self {
63        FieldValue(format!("\"{}\"", value))
64    }
65}
66
67impl Display for FieldValue {
68    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
69        write!(f, "{}", self.0)
70    }
71}