@@ -51,14 +51,14 @@ pub(crate) struct InterfaceGenerator<'a> {
5151
5252impl InterfaceGenerator < ' _ > {
5353 pub fn is_async ( kind : & FunctionKind ) -> bool {
54- matches ! (
54+ matches ! (
5555 kind,
5656 FunctionKind :: AsyncFreestanding
5757 | FunctionKind :: AsyncStatic ( _)
5858 | FunctionKind :: AsyncMethod ( _)
5959 )
6060 }
61-
61+
6262 pub ( crate ) fn define_interface_types ( & mut self , id : InterfaceId ) {
6363 let mut live = LiveTypes :: default ( ) ;
6464 live. add_interface ( self . resolve , id) ;
@@ -125,7 +125,7 @@ impl InterfaceGenerator<'_> {
125125 TypeDefKind :: Handle ( _) => {
126126 // Handles don't require a separate definition beyond what we already define for the corresponding
127127 // resource types.
128- } ,
128+ }
129129 TypeDefKind :: Future ( t) => self . type_future ( type_id, typedef_name, t, & type_def. docs ) ,
130130 _ => unreachable ! ( ) ,
131131 }
@@ -188,8 +188,9 @@ impl InterfaceGenerator<'_> {
188188 FunctionKind :: Method ( _) | FunctionKind :: AsyncMethod ( _) => {
189189 func. item_name ( ) . to_upper_camel_case ( )
190190 }
191- FunctionKind :: Constructor ( id) =>
192- self . csharp_gen . all_resources [ id] . name . to_upper_camel_case ( ) ,
191+ FunctionKind :: Constructor ( id) => {
192+ self . csharp_gen . all_resources [ id] . name . to_upper_camel_case ( )
193+ }
193194 } ;
194195
195196 let access = self . csharp_gen . access_modifier ( ) ;
@@ -214,7 +215,7 @@ impl InterfaceGenerator<'_> {
214215 } else {
215216 "void"
216217 }
217- } ,
218+ }
218219 [ result] => crate :: world_generator:: wasm_type ( * result) ,
219220 _ => unreachable ! ( ) ,
220221 } ;
@@ -345,7 +346,7 @@ impl InterfaceGenerator<'_> {
345346 self . resolve ,
346347 ty,
347348 self . csharp_gen . opts . with_wit_results ,
348- ) ;
349+ ) ;
349350 if let Some ( ty) = payload {
350351 self . csharp_gen . needs_result = true ;
351352 self . type_name_with_qualifier ( & ty, true )
@@ -362,18 +363,16 @@ impl InterfaceGenerator<'_> {
362363 let asyncified_type = match & func. kind {
363364 FunctionKind :: AsyncFreestanding
364365 | FunctionKind :: AsyncStatic ( _)
365- | FunctionKind :: AsyncMethod ( _) => {
366- match func. result {
367- None => "Task" . to_string ( ) ,
368- Some ( _ty) => format ! ( "Task<{}>" , base_type)
369- }
370- } ,
371- _ => base_type
366+ | FunctionKind :: AsyncMethod ( _) => match func. result {
367+ None => "Task" . to_string ( ) ,
368+ Some ( _ty) => format ! ( "Task<{}>" , base_type) ,
369+ } ,
370+ _ => base_type,
372371 } ;
373-
372+
374373 asyncified_type
375374 } ;
376-
375+
377376 result_type
378377 }
379378
@@ -400,7 +399,7 @@ impl InterfaceGenerator<'_> {
400399 . collect ( ) ,
401400 results. clone ( ) ,
402401 parameter_type,
403- func. result
402+ func. result ,
404403 ) ;
405404
406405 abi:: call (
@@ -439,14 +438,13 @@ impl InterfaceGenerator<'_> {
439438 FunctionKind :: Freestanding
440439 | FunctionKind :: Static ( _)
441440 | FunctionKind :: AsyncFreestanding
442- | FunctionKind :: AsyncStatic ( _) => {
443- func. item_name ( ) . to_upper_camel_case ( )
444- }
441+ | FunctionKind :: AsyncStatic ( _) => func. item_name ( ) . to_upper_camel_case ( ) ,
445442 FunctionKind :: Method ( _) | FunctionKind :: AsyncMethod ( _) => {
446443 func. item_name ( ) . to_upper_camel_case ( )
447444 }
448- FunctionKind :: Constructor ( id) =>
445+ FunctionKind :: Constructor ( id) => {
449446 self . csharp_gen . all_resources [ id] . name . to_upper_camel_case ( )
447+ }
450448 } ;
451449
452450 let modifiers = modifiers ( func, & camel_name, Direction :: Export ) ;
@@ -490,14 +488,15 @@ impl InterfaceGenerator<'_> {
490488 . collect :: < Vec < _ > > ( )
491489 . join ( ";\n " ) ;
492490
493- let wasm_result_type =
494- if async_ { "uint"
495- } else { match & sig. results [ ..] {
491+ let wasm_result_type = if async_ {
492+ "uint"
493+ } else {
494+ match & sig. results [ ..] {
496495 [ ] => "void" ,
497496 [ result] => crate :: world_generator:: wasm_type ( * result) ,
498497 _ => unreachable ! ( ) ,
499- }
500- } ;
498+ }
499+ } ;
501500
502501 let wasm_params = sig
503502 . params
@@ -569,7 +568,7 @@ impl InterfaceGenerator<'_> {
569568 ( 0 ..sig. results . len ( ) ) . map ( |i| format ! ( "p{i}" ) ) . collect ( ) ,
570569 Vec :: new ( ) ,
571570 ParameterType :: ABI ,
572- func. result
571+ func. result ,
573572 ) ;
574573
575574 abi:: post_return ( bindgen. interface_gen . resolve , func, & mut bindgen) ;
@@ -585,34 +584,36 @@ impl InterfaceGenerator<'_> {
585584 }}
586585 "#
587586 ) ;
588-
589587 }
590588
591589 if async_ {
592590 let import_module_name = & self . resolve . name_world_key ( interface_name. unwrap ( ) ) ;
593591
594- uwriteln ! ( self . csharp_interop_src,
595- r#"
592+ uwriteln ! (
593+ self . csharp_interop_src,
594+ r#"
596595 [global::System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(EntryPoint = "[callback][async-lift]{import_module_name}#{wasm_func_name}")]
597596 public static uint {camel_name}Callback(uint eventRaw, uint waitable, uint code)
598597 {{
599598 // TODO: decode the parameters
600599 return (uint)CallbackCode.Exit;
601600 }}
602- "# ) ;
601+ "#
602+ ) ;
603603
604- let task_return_param =
605- match & sig. results [ ..] {
606- [ ] => "" ,
607- [ _result] => & format ! ( "{} result" , wasm_result_type) ,
608- _ => unreachable ! ( ) ,
609- } ;
604+ let task_return_param = match & sig. results [ ..] {
605+ [ ] => "" ,
606+ [ _result] => & format ! ( "{} result" , wasm_result_type) ,
607+ _ => unreachable ! ( ) ,
608+ } ;
610609
611- uwriteln ! ( self . csharp_interop_src,
612- r#"
610+ uwriteln ! (
611+ self . csharp_interop_src,
612+ r#"
613613 [global::System.Runtime.InteropServices.DllImportAttribute("[export]{import_module_name}", EntryPoint = "[task-return]{wasm_func_name}"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute]
614614 internal static extern void {camel_name}TaskReturn({task_return_param});
615- "# ) ;
615+ "#
616+ ) ;
616617 }
617618
618619 if !matches ! ( & func. kind, FunctionKind :: Constructor ( _) ) {
@@ -779,17 +780,17 @@ impl InterfaceGenerator<'_> {
779780 self . type_name_with_qualifier ( & Type :: Id ( * id) , qualifier)
780781 }
781782 TypeDefKind :: Future ( ty) => {
782- let name =
783- ty . as_ref ( )
784- . map ( |ty| self . type_name_with_qualifier ( ty, qualifier) )
785- . unwrap_or_else ( || "" . to_owned ( ) ) ;
783+ let name = ty
784+ . as_ref ( )
785+ . map ( |ty| self . type_name_with_qualifier ( ty, qualifier) )
786+ . unwrap_or_else ( || "" . to_owned ( ) ) ;
786787 if name. is_empty ( ) {
787788 return "Task" . to_owned ( ) ;
788789 } else {
789790 return format ! ( "Task<{name}>" ) ;
790791 }
791792 }
792- _ => {
793+ _ => {
793794 if let Some ( name) = & ty. name {
794795 format ! (
795796 "{}{}" ,
@@ -1370,11 +1371,11 @@ fn modifiers(func: &Function, name: &str, direction: Direction) -> String {
13701371 } ;
13711372
13721373 let static_modifiers = match & func. kind {
1373- FunctionKind :: Freestanding
1374- | FunctionKind :: Static ( _)
1375- | FunctionKind :: AsyncFreestanding
1376- | FunctionKind :: AsyncStatic ( _) => "static" ,
1377- _ => "" ,
1374+ FunctionKind :: Freestanding
1375+ | FunctionKind :: Static ( _)
1376+ | FunctionKind :: AsyncFreestanding
1377+ | FunctionKind :: AsyncStatic ( _) => "static" ,
1378+ _ => "" ,
13781379 } ;
13791380
13801381 let abstract_modifier = if direction == Direction :: Export {
@@ -1386,7 +1387,11 @@ fn modifiers(func: &Function, name: &str, direction: Direction) -> String {
13861387 let async_modifier = match & func. kind {
13871388 FunctionKind :: AsyncMethod ( _)
13881389 | FunctionKind :: AsyncFreestanding
1389- | FunctionKind :: AsyncStatic ( _) if abstract_modifier == "" => " async" ,
1390+ | FunctionKind :: AsyncStatic ( _)
1391+ if abstract_modifier == "" =>
1392+ {
1393+ " async"
1394+ }
13901395 _ => "" ,
13911396 } ;
13921397
0 commit comments