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
46
47
use super::*;

#[derive(Debug, PartialEq, Eq, Allocative, ProvidesStaticType, Clone, Deserialize, Serialize)]
pub enum RustType {
    Null,
    Int,
    Uint,
    Float,
    Boolean,
    String,
    Value,
    List(Box<RustType>),
    Tuple(Box<RustType>, Box<RustType>),
    HashMap(Box<RustType>, Box<RustType>),
    Struct(String),
}

impl Default for RustType {
    fn default() -> RustType {
        Self::Null
    }
}

starlark_simple_value!(RustType);

#[starlark_value(type = "RustType")]
impl<'v> StarlarkValue<'v> for RustType {}

impl Display for RustType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            RustType::Null => write!(f, "Null"),
            RustType::Int => write!(f, "i32"),
            RustType::Uint => write!(f, "u32"),
            RustType::Float => write!(f, "f32"),
            RustType::Boolean => write!(f, "bool"),
            RustType::String => write!(f, "String"),
            RustType::Value => write!(f, "Value"),
            RustType::List(item_type) => write!(f, "Vec<{item_type}>"),
            RustType::Tuple(key_type, value_type) => write!(f, "({key_type},{value_type})"),
            RustType::HashMap(key_type, value_type) => {
                write!(f, "HashMap<{key_type},{value_type}>")
            }
            RustType::Struct(name) => write!(f, "{name}"),
        }
    }
}