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

Method import

crates/go/src/lib.rs:1008–1230  ·  view source on GitHub ↗
(
        &mut self,
        resolve: &Resolve,
        func: &Function,
        interface: Option<&WorldKey>,
    )

Source from the content-addressed store, hash-verified

1006
1007impl Go {
1008 fn import(
1009 &mut self,
1010 resolve: &Resolve,
1011 func: &Function,
1012 interface: Option<&WorldKey>,
1013 ) -> InterfaceData {
1014 self.visit_futures_and_streams(true, resolve, func, interface);
1015
1016 let async_ = self.opts.async_.is_async(resolve, interface, func, true);
1017
1018 let (variant, prefix) = if async_ {
1019 (AbiVariant::GuestImportAsync, "[async-lower]")
1020 } else {
1021 (AbiVariant::GuestImport, "")
1022 };
1023
1024 let sig = resolve.wasm_signature(variant, func);
1025 let import_name = &func.name;
1026 let name = func.name.to_snake_case().replace('.', "_");
1027 let (camel, has_self) = func_declaration(resolve, func);
1028
1029 let module = match interface {
1030 Some(name) => resolve.name_world_key(name),
1031 None => "$root".to_string(),
1032 };
1033
1034 let params = sig
1035 .params
1036 .iter()
1037 .enumerate()
1038 .map(|(i, param)| format!("arg{i} {}", wasm_type(*param)))
1039 .collect::<Vec<_>>()
1040 .join(", ");
1041
1042 let results = match &sig.results[..] {
1043 [] => "",
1044 [result] => wasm_type(*result),
1045 _ => unreachable!(),
1046 };
1047
1048 let mut imports = BTreeSet::new();
1049 let go_params =
1050 self.func_params(resolve, func, interface, true, &mut imports, has_self, "");
1051 let go_results = self.func_results(resolve, func, interface, true, &mut imports);
1052
1053 let raw_name = format!("wasm_import_{name}");
1054
1055 let go_param_names = has_self
1056 .then(|| "self".to_string())
1057 .into_iter()
1058 .chain(
1059 func.params
1060 .iter()
1061 .skip(if has_self { 1 } else { 0 })
1062 .map(|Param { name, .. }| name.to_lower_camel_case()),
1063 )
1064 .collect::<Vec<_>>();
1065

Callers 2

import_interfaceMethod · 0.45
import_funcsMethod · 0.45

Calls 15

func_declarationFunction · 0.85
newFunction · 0.85
remote_pkgFunction · 0.85
lower_to_memoryFunction · 0.85
lower_flatFunction · 0.85
lift_from_memoryFunction · 0.85
callFunction · 0.85
joinMethod · 0.80
mapMethod · 0.80
func_paramsMethod · 0.80
func_resultsMethod · 0.80

Tested by

no test coverage detected