@@ -160,66 +160,62 @@ pub fn tw_ffi(attr: TokenStream2, item: TokenStream2) -> Result<TokenStream2> {
160
160
docs,
161
161
} ;
162
162
163
- if let Ok ( out_dir) = env:: var ( "CARGO_WORKSPACE_DIR" ) {
164
- let bindings_dir = Path :: new ( & out_dir) . join ( "bindings" ) ;
165
- fs:: create_dir_all ( & bindings_dir) . expect ( "Failed to create bindings directory" ) ;
166
- let yaml_file_path = bindings_dir. join ( format ! ( "{}.yaml" , class) ) ;
167
-
168
- let mut config = if yaml_file_path. exists ( ) {
169
- match fs:: read_to_string ( & yaml_file_path) {
170
- Ok ( contents) => match serde_yaml:: from_str ( & contents) {
171
- Ok ( config) => config,
172
- Err ( _) => {
173
- let _ = fs:: remove_file ( & yaml_file_path) ;
174
- TWConfig {
175
- class,
176
- ..Default :: default ( )
177
- }
178
- } ,
179
- } ,
180
- Err ( _) => TWConfig {
181
- class,
182
- ..Default :: default ( )
163
+ let out_dir = env:: var ( "CARGO_WORKSPACE_DIR" ) . unwrap_or_default ( ) ;
164
+ let bindings_dir = Path :: new ( & out_dir) . join ( "bindings" ) ;
165
+ fs:: create_dir_all ( & bindings_dir) . expect ( "Failed to create bindings directory" ) ;
166
+ let yaml_file_path = bindings_dir. join ( format ! ( "{}.yaml" , class) ) ;
167
+
168
+ let mut config = if yaml_file_path. exists ( ) {
169
+ match fs:: read_to_string ( & yaml_file_path) {
170
+ Ok ( contents) => match serde_yaml:: from_str ( & contents) {
171
+ Ok ( config) => config,
172
+ Err ( _) => {
173
+ let _ = fs:: remove_file ( & yaml_file_path) ;
174
+ TWConfig {
175
+ class,
176
+ ..Default :: default ( )
177
+ }
183
178
} ,
184
- }
185
- } else {
186
- TWConfig {
179
+ } ,
180
+ Err ( _) => TWConfig {
187
181
class,
188
182
..Default :: default ( )
189
- }
190
- } ;
191
- match args. ty {
192
- Some ( TWFFIType :: StaticFunction ) => {
193
- if let Some ( idx) = config
194
- . static_functions
195
- . iter ( )
196
- . position ( |f| f. name == function. name )
197
- {
198
- config. static_functions [ idx] = function;
199
- } else {
200
- config. static_functions . push ( function) ;
201
- }
202
183
} ,
203
- Some ( TWFFIType :: Constructor ) => {
204
- update_or_append_function ( & mut config. constructors , function) ;
205
- } ,
206
- Some ( TWFFIType :: Destructor ) => {
207
- config. destructor = Some ( function) ;
208
- } ,
209
- Some ( TWFFIType :: Method ) => {
210
- update_or_append_function ( & mut config. methods , function) ;
211
- } ,
212
- Some ( TWFFIType :: Property ) => {
213
- update_or_append_function ( & mut config. properties , function) ;
214
- } ,
215
- _ => panic ! ( "Invalid FFI type" ) ,
216
184
}
217
- let yaml_output: String =
218
- serde_yaml:: to_string ( & config) . expect ( "Failed to serialize to YAML" ) ;
219
- fs:: write ( & yaml_file_path, yaml_output) . expect ( "Failed to write YAML file" ) ;
220
185
} else {
221
- panic ! ( "CARGO_WORKSPACE_DIR is not set" ) ;
186
+ TWConfig {
187
+ class,
188
+ ..Default :: default ( )
189
+ }
190
+ } ;
191
+ match args. ty {
192
+ Some ( TWFFIType :: StaticFunction ) => {
193
+ if let Some ( idx) = config
194
+ . static_functions
195
+ . iter ( )
196
+ . position ( |f| f. name == function. name )
197
+ {
198
+ config. static_functions [ idx] = function;
199
+ } else {
200
+ config. static_functions . push ( function) ;
201
+ }
202
+ } ,
203
+ Some ( TWFFIType :: Constructor ) => {
204
+ update_or_append_function ( & mut config. constructors , function) ;
205
+ } ,
206
+ Some ( TWFFIType :: Destructor ) => {
207
+ config. destructor = Some ( function) ;
208
+ } ,
209
+ Some ( TWFFIType :: Method ) => {
210
+ update_or_append_function ( & mut config. methods , function) ;
211
+ } ,
212
+ Some ( TWFFIType :: Property ) => {
213
+ update_or_append_function ( & mut config. properties , function) ;
214
+ } ,
215
+ _ => panic ! ( "Invalid FFI type" ) ,
222
216
}
217
+ let yaml_output: String = serde_yaml:: to_string ( & config) . expect ( "Failed to serialize to YAML" ) ;
218
+ fs:: write ( & yaml_file_path, yaml_output) . expect ( "Failed to write YAML file" ) ;
223
219
224
220
Ok ( item)
225
221
}
0 commit comments