MCPcopy Create free account
hub / github.com/bytecodealliance/wit-bindgen / import

Method import

crates/csharp/src/interface.rs:487–609  ·  view source on GitHub ↗
(&mut self, import_module_name: &str, func: &Function)

Source from the content-addressed store, hash-verified

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)| {

Callers 2

import_interfaceMethod · 0.45
import_funcsMethod · 0.45

Calls 13

modifiersFunction · 0.85
newFunction · 0.85
access_modifierMethod · 0.80
joinMethod · 0.80
mapMethod · 0.80
gen_import_srcMethod · 0.80
is_primative_listMethod · 0.80
wasm_typeFunction · 0.70
is_emptyMethod · 0.45
iterMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected