echo_library/types/
rust_types.rs

1use super::*;
2
3#[derive(Debug, PartialEq, Eq, Allocative, ProvidesStaticType, Clone, Deserialize, Serialize)]
4pub enum RustType {
5    Null,
6    Int,
7    Uint,
8    Float,
9    Boolean,
10    String,
11    Value,
12    List(Box<RustType>),
13    Tuple(Box<RustType>, Box<RustType>),
14    HashMap(Box<RustType>, Box<RustType>),
15    Struct(String),
16}
17
18impl Default for RustType {
19    fn default() -> RustType {
20        Self::Null
21    }
22}
23
24starlark_simple_value!(RustType);
25
26#[starlark_value(type = "RustType")]
27impl<'v> StarlarkValue<'v> for RustType {}
28
29impl Display for RustType {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        match self {
32            RustType::Null => write!(f, "Null"),
33            RustType::Int => write!(f, "i32"),
34            RustType::Uint => write!(f, "u32"),
35            RustType::Float => write!(f, "f32"),
36            RustType::Boolean => write!(f, "bool"),
37            RustType::String => write!(f, "String"),
38            RustType::Value => write!(f, "Value"),
39            RustType::List(item_type) => write!(f, "Vec<{item_type}>"),
40            RustType::Tuple(key_type, value_type) => write!(f, "({key_type},{value_type})"),
41            RustType::HashMap(key_type, value_type) => {
42                write!(f, "HashMap<{key_type},{value_type}>")
43            }
44            RustType::Struct(name) => write!(f, "{name}"),
45        }
46    }
47}