@@ -6,7 +6,7 @@ use heck::ToUpperCamelCase;
6
6
use wit_bindgen_core:: wit_parser:: {
7
7
Case , Docs , Enum , EnumCase , Field , Flag , Flags , Function , FunctionKind , Handle , Int ,
8
8
InterfaceId , Record , Resolve , Result_ , Stream , Tuple , Type , TypeDefKind , TypeId , TypeOwner ,
9
- Variant , World , WorldItem , WorldKey ,
9
+ Variant , World , WorldKey ,
10
10
} ;
11
11
use wit_bindgen_core:: { uwrite, uwriteln, Source , TypeInfo } ;
12
12
use wrpc_introspect:: { async_paths_ty, is_list_of, is_ty, rpc_func_name} ;
@@ -2545,13 +2545,13 @@ impl InterfaceGenerator<'_> {
2545
2545
let mut methods = BTreeMap :: new ( ) ;
2546
2546
let mut funcs_to_export = vec ! [ ] ;
2547
2547
2548
- traits. insert ( None , ( "Handler" . to_string ( ) , ( vec ! [ ] , vec ! [ ] ) ) ) ;
2548
+ traits. insert ( None , ( "Handler" . to_string ( ) , vec ! [ ] ) ) ;
2549
2549
2550
2550
if let Identifier :: Interface ( id, ..) = identifier {
2551
2551
for ( name, id) in & self . resolve . interfaces [ id] . types {
2552
2552
if let TypeDefKind :: Resource = self . resolve . types [ * id] . kind {
2553
2553
let camel = to_upper_camel_case ( name) ;
2554
- traits. insert ( Some ( * id) , ( camel, ( vec ! [ ] , vec ! [ ] ) ) ) ;
2554
+ traits. insert ( Some ( * id) , ( camel, vec ! [ ] ) ) ;
2555
2555
methods. insert ( * id, vec ! [ ] ) ;
2556
2556
}
2557
2557
}
@@ -2569,7 +2569,7 @@ impl InterfaceGenerator<'_> {
2569
2569
funcs_to_export. push ( func) ;
2570
2570
None
2571
2571
} ;
2572
- let ( _, ( handler_methods, client_methods ) ) = traits. get_mut ( & resource) . unwrap ( ) ;
2572
+ let ( _, handler_methods) = traits. get_mut ( & resource) . unwrap ( ) ;
2573
2573
2574
2574
let prev = mem:: take ( & mut self . src ) ;
2575
2575
self . print_docs_and_params ( func, true ) ;
@@ -2597,23 +2597,12 @@ impl InterfaceGenerator<'_> {
2597
2597
self . push_str ( "\n " ) ;
2598
2598
let trait_method = mem:: replace ( & mut self . src , prev) ;
2599
2599
handler_methods. push ( trait_method) ;
2600
-
2601
- if matches ! ( func. kind, FunctionKind :: Method ( ..) ) {
2602
- let prev = mem:: take ( & mut self . src ) ;
2603
- self . print_docs_and_params ( func, true ) ;
2604
- self . src . push_str ( " (" ) ;
2605
- for ty in func. results . iter_types ( ) {
2606
- self . print_opt_ty ( ty, true ) ;
2607
- self . src . push_str ( ", " ) ;
2608
- }
2609
- self . push_str ( "func() error, error)\n " ) ;
2610
- let trait_method = mem:: replace ( & mut self . src , prev) ;
2611
- client_methods. push ( trait_method) ;
2612
- }
2613
2600
}
2614
2601
2615
- let ( name, ( interface_methods, _) ) = traits. remove ( & None ) . unwrap ( ) ;
2616
- if interface_methods. is_empty ( ) {
2602
+ // TODO: The method serving should be propagated into the `ServeInterface`
2603
+
2604
+ let ( name, interface_methods) = traits. remove ( & None ) . unwrap ( ) ;
2605
+ if interface_methods. is_empty ( ) && traits. is_empty ( ) {
2617
2606
return false ;
2618
2607
}
2619
2608
@@ -2623,17 +2612,12 @@ impl InterfaceGenerator<'_> {
2623
2612
}
2624
2613
uwriteln ! ( self . src, "}}" ) ;
2625
2614
2626
- for ( trait_name, ( handler_methods, client_methods ) ) in traits. values ( ) {
2615
+ for ( trait_name, handler_methods) in traits. values ( ) {
2627
2616
uwriteln ! ( self . src, "type Handler{trait_name} interface {{" ) ;
2628
2617
for method in handler_methods {
2629
2618
self . src . push_str ( method) ;
2630
2619
}
2631
2620
uwriteln ! ( self . src, "}}" ) ;
2632
- uwriteln ! ( self . src, "type {trait_name} interface {{" ) ;
2633
- for method in client_methods {
2634
- self . src . push_str ( method) ;
2635
- }
2636
- uwriteln ! ( self . src, "}}" ) ;
2637
2621
}
2638
2622
2639
2623
uwriteln ! (
@@ -3017,53 +3001,15 @@ impl InterfaceGenerator<'_> {
3017
3001
3018
3002
pub fn generate_imports < ' a > (
3019
3003
& mut self ,
3020
- identifier : Identifier < ' a > ,
3004
+ _identifier : Identifier < ' a > ,
3021
3005
instance : & str ,
3022
3006
funcs : impl Iterator < Item = & ' a Function > ,
3023
3007
) {
3024
- let mut resources = BTreeMap :: new ( ) ;
3025
- match identifier {
3026
- Identifier :: Interface ( id, ..) => {
3027
- for ( name, id) in & self . resolve . interfaces [ id] . types {
3028
- if let TypeDefKind :: Resource = self . resolve . types [ * id] . kind {
3029
- let camel = to_upper_camel_case ( name) ;
3030
- resources. insert ( * id, ( camel, vec ! [ ] ) ) ;
3031
- }
3032
- }
3033
- }
3034
- Identifier :: World ( id) => {
3035
- for ( wk, wi) in & self . resolve . worlds [ id] . imports {
3036
- if let WorldItem :: Type ( id) = wi {
3037
- if let TypeDefKind :: Resource = self . resolve . types [ * id] . kind {
3038
- let WorldKey :: Name ( name) = wk else {
3039
- panic ! ( "unnamed world resource" )
3040
- } ;
3041
- let camel = to_upper_camel_case ( name) ;
3042
- resources. insert ( * id, ( camel, vec ! [ ] ) ) ;
3043
- }
3044
- }
3045
- }
3046
- }
3047
- }
3048
3008
for func in funcs {
3049
3009
if self . gen . skip . contains ( & func. name ) {
3050
3010
return ;
3051
3011
}
3052
3012
3053
- if let FunctionKind :: Method ( id) = & func. kind {
3054
- let ( _, methods) = resources. get_mut ( id) . unwrap ( ) ;
3055
- let prev = mem:: take ( & mut self . src ) ;
3056
- self . print_docs_and_params ( func, true ) ;
3057
- self . src . push_str ( " (" ) ;
3058
- for ty in func. results . iter_types ( ) {
3059
- self . print_opt_ty ( ty, true ) ;
3060
- self . src . push_str ( ", " ) ;
3061
- }
3062
- self . push_str ( "func() error, error)\n " ) ;
3063
- let trait_method = mem:: replace ( & mut self . src , prev) ;
3064
- methods. push ( trait_method) ;
3065
- }
3066
-
3067
3013
let fmt = self . deps . fmt ( ) ;
3068
3014
let wrpc = self . deps . wrpc ( ) ;
3069
3015
@@ -3181,14 +3127,6 @@ impl InterfaceGenerator<'_> {
3181
3127
func. name
3182
3128
) ;
3183
3129
}
3184
-
3185
- for ( trait_name, methods) in resources. values ( ) {
3186
- uwriteln ! ( self . src, "type {trait_name} interface {{" ) ;
3187
- for method in methods {
3188
- self . src . push_str ( method) ;
3189
- }
3190
- uwriteln ! ( self . src, "}}" ) ;
3191
- }
3192
3130
}
3193
3131
3194
3132
pub fn finish ( & mut self ) -> String {
@@ -3711,8 +3649,13 @@ func (v *{name}) WriteToIndex(w {wrpc}.ByteWriter) (func({wrpc}.IndexWriter) err
3711
3649
}
3712
3650
}
3713
3651
3714
- fn type_resource ( & mut self , _id : TypeId , _name : & str , _docs : & Docs ) {
3715
- // appropriate interfaces will be generated in imports and exports
3652
+ fn type_resource ( & mut self , _id : TypeId , name : & str , docs : & Docs ) {
3653
+ self . godoc ( docs) ;
3654
+ uwriteln ! (
3655
+ self . src,
3656
+ "type {} interface {{}}" ,
3657
+ to_upper_camel_case( name)
3658
+ ) ;
3716
3659
}
3717
3660
3718
3661
fn type_tuple ( & mut self , id : TypeId , _name : & str , tuple : & Tuple , docs : & Docs ) {
0 commit comments