@@ -1169,7 +1169,7 @@ impl {stream_and_future_support}::StreamPayload for {name} {{
1169
1169
1170
1170
let resource_methods = funcs. remove ( & Some ( * id) ) . unwrap_or ( Vec :: new ( ) ) ;
1171
1171
let trait_name = format ! ( "{path}::Guest{camel}" ) ;
1172
- self . generate_stub_impl ( & trait_name, "" , & resource_methods) ;
1172
+ self . generate_stub_impl ( & trait_name, "" , & resource_methods, interface ) ;
1173
1173
}
1174
1174
format ! ( "{path}::Guest" )
1175
1175
}
@@ -1180,7 +1180,7 @@ impl {stream_and_future_support}::StreamPayload for {name} {{
1180
1180
} ;
1181
1181
1182
1182
if !root_methods. is_empty ( ) || !extra_trait_items. is_empty ( ) {
1183
- self . generate_stub_impl ( & guest_trait, & extra_trait_items, & root_methods) ;
1183
+ self . generate_stub_impl ( & guest_trait, & extra_trait_items, & root_methods, interface ) ;
1184
1184
}
1185
1185
}
1186
1186
@@ -1189,6 +1189,7 @@ impl {stream_and_future_support}::StreamPayload for {name} {{
1189
1189
trait_name : & str ,
1190
1190
extra_trait_items : & str ,
1191
1191
funcs : & [ & Function ] ,
1192
+ interface : Option < ( InterfaceId , & WorldKey ) > ,
1192
1193
) {
1193
1194
uwriteln ! ( self . src, "impl {trait_name} for Stub {{" ) ;
1194
1195
self . src . push_str ( extra_trait_items) ;
@@ -1197,7 +1198,19 @@ impl {stream_and_future_support}::StreamPayload for {name} {{
1197
1198
if self . gen . skip . contains ( & func. name ) {
1198
1199
continue ;
1199
1200
}
1201
+ let async_ = match & self . gen . opts . async_ {
1202
+ AsyncConfig :: None => false ,
1203
+ AsyncConfig :: All => true ,
1204
+ AsyncConfig :: Some { exports, .. } => {
1205
+ exports. contains ( & if let Some ( ( _, key) ) = interface {
1206
+ format ! ( "{}#{}" , self . resolve. name_world_key( key) , func. name)
1207
+ } else {
1208
+ func. name . clone ( )
1209
+ } )
1210
+ }
1211
+ } ;
1200
1212
let mut sig = FnSig {
1213
+ async_,
1201
1214
use_item_name : true ,
1202
1215
private : true ,
1203
1216
..Default :: default ( )
@@ -1206,8 +1219,14 @@ impl {stream_and_future_support}::StreamPayload for {name} {{
1206
1219
sig. self_arg = Some ( "&self" . into ( ) ) ;
1207
1220
sig. self_is_first_param = true ;
1208
1221
}
1209
- self . print_signature ( func, true , & sig, true ) ;
1210
- self . src . push_str ( "{ unreachable!() }\n " ) ;
1222
+ self . print_signature ( func, true , & sig, false ) ;
1223
+ let call = if async_ {
1224
+ let async_support = self . path_to_async_support ( ) ;
1225
+ format ! ( "{{ #[allow(unreachable_code)]{async_support}::futures::future::ready(unreachable!()) }}\n " )
1226
+ } else {
1227
+ "{ unreachable!() }\n " . into ( )
1228
+ } ;
1229
+ self . src . push_str ( & call) ;
1211
1230
}
1212
1231
1213
1232
self . src . push_str ( "}\n " ) ;
@@ -1273,7 +1292,11 @@ impl {stream_and_future_support}::StreamPayload for {name} {{
1273
1292
) -> Vec < String > {
1274
1293
let params = self . print_docs_and_params ( func, params_owned, sig, use_async_sugar) ;
1275
1294
if let FunctionKind :: Constructor ( _) = & func. kind {
1276
- self . push_str ( " -> Self" )
1295
+ self . push_str ( if sig. async_ && !use_async_sugar {
1296
+ " -> impl ::core::future::Future<Output = Self>"
1297
+ } else {
1298
+ " -> Self"
1299
+ } )
1277
1300
} else {
1278
1301
self . print_results ( & func. results , sig. async_ && !use_async_sugar) ;
1279
1302
}
0 commit comments