1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
5pub enum DefaultValue {
6 BoolLiteral(bool),
7 StringLiteral(String),
8 IntLiteral(i64),
9 FloatLiteral(f64),
10 EnumVariant(String),
11 Empty,
13 None,
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct ApiSurface {
20 pub crate_name: String,
21 pub version: String,
22 pub types: Vec<TypeDef>,
23 pub functions: Vec<FunctionDef>,
24 pub enums: Vec<EnumDef>,
25 pub errors: Vec<ErrorDef>,
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct TypeDef {
31 pub name: String,
32 pub rust_path: String,
33 pub fields: Vec<FieldDef>,
34 pub methods: Vec<MethodDef>,
35 pub is_opaque: bool,
36 pub is_clone: bool,
37 pub doc: String,
38 #[serde(default)]
39 pub cfg: Option<String>,
40 #[serde(default)]
43 pub is_trait: bool,
44 #[serde(default)]
47 pub has_default: bool,
48 #[serde(default)]
52 pub has_stripped_cfg_fields: bool,
53 #[serde(default)]
56 pub is_return_type: bool,
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
61pub struct FieldDef {
62 pub name: String,
63 pub ty: TypeRef,
64 pub optional: bool,
65 pub default: Option<String>,
66 pub doc: String,
67 #[serde(default)]
70 pub sanitized: bool,
71 #[serde(default)]
74 pub is_boxed: bool,
75 #[serde(default)]
78 pub type_rust_path: Option<String>,
79 #[serde(default)]
82 pub cfg: Option<String>,
83 #[serde(default)]
85 pub typed_default: Option<DefaultValue>,
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
90pub struct MethodDef {
91 pub name: String,
92 pub params: Vec<ParamDef>,
93 pub return_type: TypeRef,
94 pub is_async: bool,
95 pub is_static: bool,
96 pub error_type: Option<String>,
97 pub doc: String,
98 pub receiver: Option<ReceiverKind>,
99 #[serde(default)]
102 pub sanitized: bool,
103 #[serde(default)]
106 pub trait_source: Option<String>,
107 #[serde(default)]
110 pub returns_ref: bool,
111}
112
113#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
115pub enum ReceiverKind {
116 Ref,
117 RefMut,
118 Owned,
119}
120
121#[derive(Debug, Clone, Serialize, Deserialize)]
123pub struct FunctionDef {
124 pub name: String,
125 pub rust_path: String,
126 pub params: Vec<ParamDef>,
127 pub return_type: TypeRef,
128 pub is_async: bool,
129 pub error_type: Option<String>,
130 pub doc: String,
131 #[serde(default)]
132 pub cfg: Option<String>,
133 #[serde(default)]
135 pub sanitized: bool,
136 #[serde(default)]
139 pub returns_ref: bool,
140}
141
142#[derive(Debug, Clone, Serialize, Deserialize)]
144pub struct ParamDef {
145 pub name: String,
146 pub ty: TypeRef,
147 pub optional: bool,
148 pub default: Option<String>,
149 #[serde(default)]
151 pub sanitized: bool,
152 #[serde(default)]
154 pub typed_default: Option<DefaultValue>,
155}
156
157#[derive(Debug, Clone, Serialize, Deserialize)]
159pub struct EnumDef {
160 pub name: String,
161 pub rust_path: String,
162 pub variants: Vec<EnumVariant>,
163 pub doc: String,
164 #[serde(default)]
165 pub cfg: Option<String>,
166}
167
168#[derive(Debug, Clone, Serialize, Deserialize)]
170pub struct EnumVariant {
171 pub name: String,
172 pub fields: Vec<FieldDef>,
173 pub doc: String,
174 #[serde(default)]
176 pub is_default: bool,
177}
178
179#[derive(Debug, Clone, Serialize, Deserialize)]
181pub struct ErrorDef {
182 pub name: String,
183 pub rust_path: String,
184 pub variants: Vec<ErrorVariant>,
185 pub doc: String,
186}
187
188#[derive(Debug, Clone, Serialize, Deserialize)]
190pub struct ErrorVariant {
191 pub name: String,
192 pub message_template: Option<String>,
194 #[serde(default)]
196 pub fields: Vec<FieldDef>,
197 #[serde(default)]
199 pub has_source: bool,
200 #[serde(default)]
202 pub has_from: bool,
203 #[serde(default)]
205 pub is_unit: bool,
206 pub doc: String,
207}
208
209#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
211pub enum TypeRef {
212 Primitive(PrimitiveType),
213 String,
214 Char,
216 Bytes,
217 Optional(Box<TypeRef>),
218 Vec(Box<TypeRef>),
219 Map(Box<TypeRef>, Box<TypeRef>),
220 Named(String),
221 Path,
222 Unit,
223 Json,
224 Duration,
225}
226
227#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
229pub enum PrimitiveType {
230 Bool,
231 U8,
232 U16,
233 U32,
234 U64,
235 I8,
236 I16,
237 I32,
238 I64,
239 F32,
240 F64,
241 Usize,
242 Isize,
243}