1use std::{
2 any::Any,
3 fmt::Debug,
4 time::{Duration, SystemTime},
5};
6
7use crate::common::{types, types::Type};
8
9#[derive(Clone, Debug, PartialEq)]
10pub enum CelVal {
11 Unspecified,
12 Error,
13 Dyn,
14 Any,
15 Boolean(bool),
16 Bytes(Vec<u8>),
17 Float(f64),
18 Duration(Duration),
19 Int(i64),
20 List,
21 Map,
22 Null,
23 String(String),
24 Timestamp(SystemTime),
25 Type,
26 UInt(u64),
27 Unknown,
28}
29
30pub trait Val {
31 fn get_type(&self) -> Type<'_>;
32
33 fn into_inner(self) -> Box<dyn Any>;
34}
35
36impl Val for CelVal {
37 fn get_type(&self) -> Type<'_> {
38 match self {
39 CelVal::Unspecified => Type::new_unspecified_type("unspecified"),
40 CelVal::Error => types::ERROR_TYPE,
41 CelVal::Dyn => types::DYN_TYPE,
42 CelVal::Any => types::ANY_TYPE,
43 CelVal::Boolean(_) => types::BOOL_TYPE,
44 CelVal::Bytes(_) => types::BYTES_TYPE,
45 CelVal::Float(_) => types::FLOAT_TYPE,
46 CelVal::Duration(_) => types::DURATION_TYPE,
47 CelVal::Int(_) => types::INT_TYPE,
48 CelVal::List => types::LIST_TYPE,
49 CelVal::Map => types::MAP_TYPE,
50 CelVal::Null => types::NULL_TYPE,
51 CelVal::String(_) => types::STRING_TYPE,
52 CelVal::Timestamp(_) => types::TIMESTAMP_TYPE,
53 CelVal::Type => types::TYPE_TYPE,
54 CelVal::UInt(_) => types::UINT_TYPE,
55 CelVal::Unknown => types::UNKNOWN_TYPE,
56 }
57 }
58
59 fn into_inner(self) -> Box<dyn Any> {
60 match self {
61 CelVal::Unspecified => todo!(),
62 CelVal::Error => todo!(),
63 CelVal::Dyn => todo!(),
64 CelVal::Any => todo!(),
65 CelVal::Boolean(b) => Box::new(b),
66 CelVal::Bytes(b) => Box::new(b),
67 CelVal::Float(d) => Box::new(d),
68 CelVal::Duration(d) => Box::new(d),
69 CelVal::Int(i) => Box::new(i),
70 CelVal::List => todo!(),
71 CelVal::Map => todo!(),
72 CelVal::Null => todo!(),
73 CelVal::String(s) => Box::new(s),
74 CelVal::Timestamp(t) => Box::new(t),
75 CelVal::Type => todo!(),
76 CelVal::UInt(u) => Box::new(u),
77 CelVal::Unknown => todo!(),
78 }
79 }
80}