@@ -191,7 +191,7 @@ pub fn componentize_bindgen(resolve: &Resolve, wid: WorldId) -> Result<Component
191
191
for ( specifier, by_resource) in by_specifier_by_resource {
192
192
let mut specifier_list = Vec :: new ( ) ;
193
193
for ( resource, items) in by_resource {
194
- let item = items. iter ( ) . next ( ) . unwrap ( ) ;
194
+ let item = items. first ( ) . unwrap ( ) ;
195
195
if let Some ( resource) = resource {
196
196
let export_name = resource. to_upper_camel_case ( ) ;
197
197
let binding_name = binding_name ( & export_name, & item. iface_name ) ;
@@ -241,7 +241,7 @@ pub fn componentize_bindgen(resolve: &Resolve, wid: WorldId) -> Result<Component
241
241
if let TypeDefKind :: Resource = & ty. kind {
242
242
let iface_prefix = interface_name ( resolve, * iface_id)
243
243
. map ( |s| format ! ( "{s}$" ) )
244
- . unwrap_or_else ( String :: new ) ;
244
+ . unwrap_or_default ( ) ;
245
245
let resource_name_camel = ty. name . as_ref ( ) . unwrap ( ) . to_lower_camel_case ( ) ;
246
246
let resource_name_kebab = ty. name . as_ref ( ) . unwrap ( ) . to_kebab_case ( ) ;
247
247
let module_name = format ! ( "[export]{key_name}" ) ;
@@ -295,11 +295,8 @@ pub fn componentize_bindgen(resolve: &Resolve, wid: WorldId) -> Result<Component
295
295
WorldItem :: Function ( _) => { }
296
296
WorldItem :: Type ( id) => {
297
297
let ty = & resolve. types [ * id] ;
298
- match ty. kind {
299
- TypeDefKind :: Resource => {
300
- imported_resource_modules. insert ( * id, key_name. clone ( ) ) ;
301
- }
302
- _ => { }
298
+ if ty. kind == TypeDefKind :: Resource {
299
+ imported_resource_modules. insert ( * id, key_name. clone ( ) ) ;
303
300
}
304
301
}
305
302
}
@@ -390,7 +387,7 @@ pub fn componentize_bindgen(resolve: &Resolve, wid: WorldId) -> Result<Component
390
387
impl JsBindgen < ' _ > {
391
388
fn intrinsic ( & mut self , intrinsic : Intrinsic ) -> String {
392
389
self . all_intrinsics . insert ( intrinsic) ;
393
- return intrinsic. name ( ) . to_string ( ) ;
390
+ intrinsic. name ( ) . to_string ( )
394
391
}
395
392
396
393
fn exports_bindgen (
@@ -448,14 +445,7 @@ impl JsBindgen<'_> {
448
445
match export {
449
446
WorldItem :: Function ( func) => {
450
447
let local_name = self . local_names . create_once ( & func. name ) . to_string ( ) ;
451
- self . export_bindgen (
452
- name. into ( ) ,
453
- false ,
454
- None ,
455
- & local_name,
456
- StringEncoding :: UTF8 ,
457
- func,
458
- ) ;
448
+ self . export_bindgen ( name, false , None , & local_name, StringEncoding :: UTF8 , func) ;
459
449
self . esm_bindgen . add_export_func (
460
450
None ,
461
451
local_name. to_string ( ) ,
@@ -484,7 +474,7 @@ impl JsBindgen<'_> {
484
474
interface_name ( self . resolve , * id) ,
485
475
& local_name,
486
476
StringEncoding :: UTF8 ,
487
- & func,
477
+ func,
488
478
) ;
489
479
self . esm_bindgen . add_export_func (
490
480
Some ( name) ,
@@ -501,7 +491,7 @@ impl JsBindgen<'_> {
501
491
let local_name = self
502
492
. local_names
503
493
. get_or_create (
504
- & format ! ( "resource:{resource_name}" ) ,
494
+ format ! ( "resource:{resource_name}" ) ,
505
495
& resource_name,
506
496
)
507
497
. 0
@@ -512,10 +502,10 @@ impl JsBindgen<'_> {
512
502
interface_name ( self . resolve , * id) ,
513
503
& local_name,
514
504
StringEncoding :: UTF8 ,
515
- & func,
505
+ func,
516
506
) ;
517
507
self . esm_bindgen . ensure_exported_resource (
518
- Some ( & name) ,
508
+ Some ( name) ,
519
509
local_name,
520
510
resource_name,
521
511
) ;
@@ -547,7 +537,7 @@ impl JsBindgen<'_> {
547
537
. as_ref ( )
548
538
. unwrap ( )
549
539
. to_upper_camel_case ( ) ,
550
- & iface_name,
540
+ iface_name,
551
541
) ;
552
542
553
543
uwriteln ! ( self . src, "\n class import_{name} {{" ) ;
@@ -568,7 +558,7 @@ impl JsBindgen<'_> {
568
558
let prefix = iface_name
569
559
. as_deref ( )
570
560
. map ( |s| format ! ( "{s}$" ) )
571
- . unwrap_or ( String :: new ( ) ) ;
561
+ . unwrap_or_default ( ) ;
572
562
573
563
let resource_symbol = self . intrinsic ( Intrinsic :: SymbolResourceHandle ) ;
574
564
let dispose_symbol = self . intrinsic ( Intrinsic :: SymbolDispose ) ;
@@ -646,44 +636,38 @@ impl JsBindgen<'_> {
646
636
}
647
637
WorldItem :: Type ( id) => {
648
638
let ty = & self . resolve . types [ * id] ;
649
- match ty. kind {
650
- TypeDefKind :: Resource => {
651
- self . resource_directions
652
- . insert ( * id, AbiVariant :: GuestImport ) ;
653
-
654
- let resource_name = ty. name . as_ref ( ) . unwrap ( ) ;
655
-
656
- let mut resource_fns = Vec :: new ( ) ;
657
- for ( _, impt) in & self . resolve . worlds [ self . world ] . imports {
658
- match impt {
659
- WorldItem :: Function ( function) => {
660
- let stripped = if let Some ( stripped) =
661
- function. name . strip_prefix ( "[constructor]" )
662
- {
663
- stripped
664
- } else if let Some ( stripped) =
665
- function. name . strip_prefix ( "[method]" )
666
- {
667
- stripped
668
- } else if let Some ( stripped) =
669
- function. name . strip_prefix ( "[static]" )
670
- {
671
- stripped
672
- } else {
673
- continue ;
674
- } ;
675
-
676
- if stripped. starts_with ( resource_name) {
677
- resource_fns. push ( ( function. name . as_str ( ) , function) ) ;
678
- }
679
- }
680
- _ => { }
639
+ if ty. kind == TypeDefKind :: Resource {
640
+ self . resource_directions
641
+ . insert ( * id, AbiVariant :: GuestImport ) ;
642
+
643
+ let resource_name = ty. name . as_ref ( ) . unwrap ( ) ;
644
+
645
+ let mut resource_fns = Vec :: new ( ) ;
646
+ for ( _, impt) in & self . resolve . worlds [ self . world ] . imports {
647
+ if let WorldItem :: Function ( function) = impt {
648
+ let stripped = if let Some ( stripped) =
649
+ function. name . strip_prefix ( "[constructor]" )
650
+ {
651
+ stripped
652
+ } else if let Some ( stripped) =
653
+ function. name . strip_prefix ( "[method]" )
654
+ {
655
+ stripped
656
+ } else if let Some ( stripped) =
657
+ function. name . strip_prefix ( "[static]" )
658
+ {
659
+ stripped
660
+ } else {
661
+ continue ;
662
+ } ;
663
+
664
+ if stripped. starts_with ( resource_name) {
665
+ resource_fns. push ( ( function. name . as_str ( ) , function) ) ;
681
666
}
682
667
}
683
-
684
- self . resource_bindgen ( * id, "$root" , & None , resource_fns) ;
685
668
}
686
- _ => { }
669
+
670
+ self . resource_bindgen ( * id, "$root" , & None , resource_fns) ;
687
671
}
688
672
}
689
673
} ;
@@ -1112,8 +1096,7 @@ impl EsmBindgen {
1112
1096
iface = match iface. get_mut ( & iface_id_or_kebab) . unwrap ( ) {
1113
1097
Binding :: Interface ( iface) => iface,
1114
1098
Binding :: Resource ( _) | Binding :: Local ( _) => panic ! (
1115
- "Exported interface {} cannot be both a function and an interface or resource" ,
1116
- iface_id_or_kebab
1099
+ "Exported interface {iface_id_or_kebab} cannot be both a function and an interface or resource"
1117
1100
) ,
1118
1101
} ;
1119
1102
}
@@ -1143,8 +1126,7 @@ impl EsmBindgen {
1143
1126
iface = match iface. get_mut ( & iface_id_or_kebab) . unwrap ( ) {
1144
1127
Binding :: Interface ( iface) => iface,
1145
1128
Binding :: Resource ( _) | Binding :: Local ( _) => panic ! (
1146
- "Exported interface {} cannot be both a function and an interface or resource" ,
1147
- iface_id_or_kebab
1129
+ "Exported interface {iface_id_or_kebab} cannot be both a function and an interface or resource"
1148
1130
) ,
1149
1131
} ;
1150
1132
}
@@ -1158,7 +1140,7 @@ impl EsmBindgen {
1158
1140
let expt_name_sans_version = if let Some ( version_idx) = expt_name. find ( '@' ) {
1159
1141
& expt_name[ 0 ..version_idx]
1160
1142
} else {
1161
- & expt_name
1143
+ expt_name
1162
1144
} ;
1163
1145
if let Some ( alias) = interface_name_from_string ( expt_name_sans_version) {
1164
1146
if !self . exports . contains_key ( & alias)
@@ -1178,7 +1160,7 @@ impl EsmBindgen {
1178
1160
) {
1179
1161
// TODO: bring back these validations of imports
1180
1162
// including using the flattened bindings
1181
- if self . exports . len ( ) > 0 {
1163
+ if ! self . exports . is_empty ( ) {
1182
1164
// error handling
1183
1165
uwriteln ! ( output, "
1184
1166
class BindingsError extends Error {{
@@ -1328,12 +1310,9 @@ fn interface_name_from_string(name: &str) -> Option<String> {
1328
1310
let path_idx = name. rfind ( '/' ) ?;
1329
1311
let name = & name[ path_idx + 1 ..] ;
1330
1312
let at_idx = name. rfind ( '@' ) ;
1331
- let alias = name[ ..at_idx. unwrap_or_else ( || name. len ( ) ) ] . to_lower_camel_case ( ) ;
1313
+ let alias = name[ ..at_idx. unwrap_or ( name. len ( ) ) ] . to_lower_camel_case ( ) ;
1332
1314
let iface_name = Some ( if let Some ( at_idx) = at_idx {
1333
- format ! (
1334
- "{alias}_{}" ,
1335
- name[ at_idx + 1 ..] . replace( '.' , "_" ) . replace( '-' , "_" )
1336
- )
1315
+ format ! ( "{alias}_{}" , name[ at_idx + 1 ..] . replace( [ '.' , '-' ] , "_" ) )
1337
1316
} else {
1338
1317
alias
1339
1318
} ) ;
@@ -1343,23 +1322,21 @@ fn interface_name_from_string(name: &str) -> Option<String> {
1343
1322
fn binding_name ( func_name : & str , iface_name : & Option < String > ) -> String {
1344
1323
match iface_name {
1345
1324
Some ( iface_name) => format ! ( "{iface_name}${func_name}" ) ,
1346
- None => format ! ( "{ func_name}" ) ,
1325
+ None => func_name. to_string ( ) ,
1347
1326
}
1348
1327
}
1349
1328
1350
1329
/// Extract success and error types from a given optional type, if it is a Result
1351
- pub fn get_result_types < ' a > (
1352
- resolve : & ' a Resolve ,
1330
+ pub fn get_result_types (
1331
+ resolve : & Resolve ,
1353
1332
return_type : Option < Type > ,
1354
- ) -> Option < ( Option < & ' a Type > , Option < & ' a Type > ) > {
1333
+ ) -> Option < ( Option < & Type > , Option < & Type > ) > {
1355
1334
match return_type {
1356
1335
None => None ,
1357
- Some ( ty) => match ty {
1358
- Type :: Id ( id) => match & resolve. types [ id] . kind {
1359
- TypeDefKind :: Result ( r) => Some ( ( r. ok . as_ref ( ) , r. err . as_ref ( ) ) ) ,
1360
- _ => None ,
1361
- } ,
1336
+ Some ( Type :: Id ( id) ) => match & resolve. types [ id] . kind {
1337
+ TypeDefKind :: Result ( r) => Some ( ( r. ok . as_ref ( ) , r. err . as_ref ( ) ) ) ,
1362
1338
_ => None ,
1363
1339
} ,
1340
+ _ => None ,
1364
1341
}
1365
1342
}
0 commit comments