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