(&mut self, import_module_name: &str, func: &Function)
| 485 | } |
| 486 | |
| 487 | pub(crate) fn import(&mut self, import_module_name: &str, func: &Function) { |
| 488 | let camel_name = match &func.kind { |
| 489 | FunctionKind::Freestanding |
| 490 | | FunctionKind::Static(_) |
| 491 | | FunctionKind::AsyncFreestanding |
| 492 | | FunctionKind::AsyncStatic(_) => func.item_name().to_upper_camel_case(), |
| 493 | FunctionKind::Method(_) | FunctionKind::AsyncMethod(_) => { |
| 494 | func.item_name().to_upper_camel_case() |
| 495 | } |
| 496 | FunctionKind::Constructor(id) => { |
| 497 | self.csharp_gen.all_resources[id].name.to_upper_camel_case() |
| 498 | } |
| 499 | }; |
| 500 | |
| 501 | let access = self.csharp_gen.access_modifier(); |
| 502 | |
| 503 | let modifiers = modifiers(func, &camel_name, Direction::Import); |
| 504 | |
| 505 | let interop_camel_name = func.item_name().to_upper_camel_case(); |
| 506 | |
| 507 | let sig = self.resolve.wasm_signature(AbiVariant::GuestImport, func); |
| 508 | |
| 509 | let is_async = matches!( |
| 510 | func.kind, |
| 511 | FunctionKind::AsyncFreestanding |
| 512 | | FunctionKind::AsyncStatic(_) |
| 513 | | FunctionKind::AsyncMethod(_) |
| 514 | ); |
| 515 | |
| 516 | let mut wasm_result_type = match &sig.results[..] { |
| 517 | [] => { |
| 518 | if is_async { |
| 519 | "uint" |
| 520 | } else { |
| 521 | "void" |
| 522 | } |
| 523 | } |
| 524 | [result] => crate::world_generator::wasm_type(*result), |
| 525 | _ => unreachable!(), |
| 526 | }; |
| 527 | |
| 528 | let (result_type, results) = self.func_payload_and_return_type(func); |
| 529 | |
| 530 | let is_async = InterfaceGenerator::is_async(&func.kind); |
| 531 | |
| 532 | let requires_async_return_buffer_param = is_async && !sig.results.is_empty(); |
| 533 | let sig_unsafe = if requires_async_return_buffer_param { |
| 534 | "unsafe " |
| 535 | } else { |
| 536 | "" |
| 537 | }; |
| 538 | |
| 539 | let wasm_params: String = { |
| 540 | let param_list = sig |
| 541 | .params |
| 542 | .iter() |
| 543 | .enumerate() |
| 544 | .map(|(i, param)| { |
no test coverage detected