1use std::hash::{Hash, Hasher};
2
3#[cfg(feature = "os")]
4use serde::{Deserialize, Serialize};
5
6#[derive(Clone, Debug)]
7#[cfg_attr(feature = "os", derive(Serialize, Deserialize))]
8pub struct Unit {
9 pub name: String,
10 pub value: Option<Value>,
11}
12
13impl PartialEq for Unit {
14 fn eq(&self, other: &Self) -> bool {
15 self.name.eq(&other.name)
16 }
17}
18
19impl Eq for Unit {}
20
21impl Hash for Unit {
22 fn hash<H: Hasher>(&self, state: &mut H) {
23 self.name.hash(state)
24 }
25}
26
27#[derive(Clone, Debug)]
28#[cfg_attr(feature = "os", derive(Serialize, Deserialize))]
29pub enum Value {
30 Real(f64),
31 Keyword(String),
32}
33
34impl Value {
35 pub fn is_real(&self) -> bool {
36 match &self {
37 Self::Real(_) => true,
38 Self::Keyword(_) => false,
39 }
40 }
41
42 pub fn is_keyword(&self) -> bool {
43 match &self {
44 Self::Real(_) => false,
45 Self::Keyword(_) => true,
46 }
47 }
48}