use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ValuesMap {
#[serde(rename = "type")]
pub value_type: ValueType,
pub values: Vec<Value>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ValueType(
#[serde(deserialize_with = "crate::string_within_range_inclusive::<1, 128, _>")] pub String,
);
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Value {
Integer(i64),
Number(f64),
Boolean(bool),
Point(Point),
String(String),
}
impl PartialEq for Value {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Integer(s), Self::Integer(o)) => s == o,
(Self::Boolean(s), Self::Boolean(o)) => s == o,
(Self::Point(s), Self::Point(o)) => s == o,
(Self::String(s), Self::String(o)) => s == o,
(Self::Number(s), Self::Number(o)) if s.is_nan() && o.is_nan() => true,
(Self::Number(s), Self::Number(o)) => s == o,
_ => false,
}
}
}
impl Eq for Value {}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub(crate) enum ValueKind {
Integer,
Number,
Boolean,
Point,
String,
Any,
}
impl Value {
pub(crate) fn kind(&self) -> ValueKind {
match self {
Value::Integer(_) => ValueKind::Integer,
Value::Number(_) => ValueKind::Number,
Value::Boolean(_) => ValueKind::Boolean,
Value::Point(_) => ValueKind::Point,
Value::String(_) => ValueKind::String,
}
}
}
#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct Point {
pub x: f32,
pub y: f32,
}
impl Point {
pub fn new(x: f32, y: f32) -> Self {
Self { x, y }
}
}