pipeline_script/ast/
data.rs

1use crate::ast::r#type::Type;
2
3#[derive(Debug, Clone)]
4pub enum Data {
5    String(String),
6    Int32(i32),
7    Int64(i64),
8    Float32(f32),
9    Float64(f64),
10    Boolean(bool),
11    Usize(usize),
12    IDSet(Vec<String>),
13    Array(Vec<Data>),
14    Map(Vec<(Data, Data)>),
15    Type(Type),
16    None,
17}
18impl Data {
19    pub fn as_str(&self) -> Option<&str> {
20        match self {
21            Data::String(s) => Some(s),
22            _ => None,
23        }
24    }
25    pub fn as_bool(&self) -> Option<bool> {
26        match self {
27            Data::Boolean(b) => Some(*b),
28            _ => None,
29        }
30    }
31    pub fn as_type(&self) -> Option<&Type> {
32        match self {
33            Data::Type(t) => Some(t),
34            _ => None,
35        }
36    }
37    pub fn as_i64(&self) -> Option<i64> {
38        match self {
39            Data::Int64(i) => Some(*i),
40            _ => None,
41        }
42    }
43    pub fn as_array(&self) -> Option<&Vec<Data>> {
44        match self {
45            Data::Array(a) => Some(a),
46            _ => None,
47        }
48    }
49}
50impl From<String> for Data {
51    fn from(value: String) -> Self {
52        Self::String(value)
53    }
54}
55
56impl From<i32> for Data {
57    fn from(value: i32) -> Self {
58        Self::Int32(value)
59    }
60}