Skip to main content

ergo_runtime/common/
value.rs

1#[derive(Debug, Clone, PartialEq)]
2pub enum ValueType {
3    Number,
4    Series,
5    Bool,
6    String,
7}
8
9#[derive(Debug, Clone, PartialEq)]
10pub enum PrimitiveKind {
11    Compute,
12}
13
14#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
15pub enum Value {
16    Number(f64),
17    Series(Vec<f64>),
18    Bool(bool),
19    String(String),
20}
21
22impl Value {
23    pub fn value_type(&self) -> ValueType {
24        match self {
25            Value::Number(_) => ValueType::Number,
26            Value::Series(_) => ValueType::Series,
27            Value::Bool(_) => ValueType::Bool,
28            Value::String(_) => ValueType::String,
29        }
30    }
31
32    pub fn as_number(&self) -> Option<f64> {
33        match self {
34            Value::Number(n) => Some(*n),
35            _ => None,
36        }
37    }
38
39    pub fn as_series(&self) -> Option<&Vec<f64>> {
40        match self {
41            Value::Series(s) => Some(s),
42            _ => None,
43        }
44    }
45
46    pub fn as_bool(&self) -> Option<bool> {
47        match self {
48            Value::Bool(b) => Some(*b),
49            _ => None,
50        }
51    }
52
53    pub fn as_string(&self) -> Option<&str> {
54        match self {
55            Value::String(s) => Some(s),
56            _ => None,
57        }
58    }
59}