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
48
49
50
51
52
53
54
55
56
57
58
use serde::{Deserialize, Serialize};
use strum_macros::ToString;
pub type JsonABI = Vec<Function>;
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Function {
#[serde(rename = "type")]
pub type_field: String,
pub inputs: Vec<Property>,
pub name: String,
pub outputs: Vec<Property>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Property {
pub name: String,
#[serde(rename = "type")]
pub type_field: String,
pub components: Option<Vec<Property>>,
}
const STRUCT_KEYWORD: &str = "struct ";
const ENUM_KEYWORD: &str = "enum ";
impl Property {
pub fn is_enum_type(&self) -> bool {
self.type_field.starts_with(ENUM_KEYWORD)
}
pub fn is_struct_type(&self) -> bool {
self.type_field.starts_with(STRUCT_KEYWORD)
}
pub fn is_custom_type(&self) -> bool {
self.is_enum_type() || self.is_struct_type()
}
}
#[derive(Debug, Clone, ToString, PartialEq, Eq)]
#[strum(serialize_all = "lowercase")]
pub enum CustomType {
Struct,
Enum,
}