openleadr_wire/
values_map.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
10pub struct ValuesMap {
11 #[serde(rename = "type")]
15 pub value_type: ValueType,
16 pub values: Vec<Value>,
18}
19
20#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
21pub struct ValueType(
22 #[serde(deserialize_with = "crate::string_within_range_inclusive::<1, 128, _>")] pub String,
23);
24
25#[derive(Clone, Debug, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum Value {
28 Integer(i64),
29 Number(f64),
30 Boolean(bool),
31 Point(Point),
32 String(String),
33}
34
35impl PartialEq for Value {
36 fn eq(&self, other: &Self) -> bool {
37 match (self, other) {
38 (Self::Integer(s), Self::Integer(o)) => s == o,
39 (Self::Boolean(s), Self::Boolean(o)) => s == o,
40 (Self::Point(s), Self::Point(o)) => s == o,
41 (Self::String(s), Self::String(o)) => s == o,
42 (Self::Number(s), Self::Number(o)) if s.is_nan() && o.is_nan() => true,
43 (Self::Number(s), Self::Number(o)) => s == o,
44 _ => false,
45 }
46 }
47}
48
49impl Eq for Value {}
50
51#[derive(Debug, Copy, Clone, PartialEq, Eq)]
52pub(crate) enum ValueKind {
53 Integer,
54 Number,
55 Boolean,
56 Point,
57 String,
58 Any,
59}
60
61impl Value {
62 pub(crate) fn kind(&self) -> ValueKind {
63 match self {
64 Value::Integer(_) => ValueKind::Integer,
65 Value::Number(_) => ValueKind::Number,
66 Value::Boolean(_) => ValueKind::Boolean,
67 Value::Point(_) => ValueKind::Point,
68 Value::String(_) => ValueKind::String,
69 }
70 }
71}
72
73#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
74pub struct Point {
75 pub x: f32,
77 pub y: f32,
79}
80
81impl Point {
82 pub fn new(x: f32, y: f32) -> Self {
83 Self { x, y }
84 }
85}