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

Method generate_stub

crates/rust/src/interface.rs:1329–1365  ·  view source on GitHub ↗
(
        &mut self,
        interface: Option<(InterfaceId, &WorldKey)>,
        funcs: impl Iterator<Item = &'a Function> + Clone,
    )

Source from the content-addressed store, hash-verified

1327 }
1328
1329 pub fn generate_stub<'a>(
1330 &mut self,
1331 interface: Option<(InterfaceId, &WorldKey)>,
1332 funcs: impl Iterator<Item = &'a Function> + Clone,
1333 ) {
1334 let mut funcs = super::group_by_resource(funcs.clone());
1335
1336 let root_methods = funcs.remove(&None).unwrap_or(Vec::new());
1337
1338 let mut extra_trait_items = String::new();
1339 let guest_trait = match interface {
1340 Some((id, _)) => {
1341 let path = self.path_to_interface(id).unwrap();
1342 for (name, id) in self.resolve.interfaces[id].types.iter() {
1343 match self.resolve.types[*id].kind {
1344 TypeDefKind::Resource => {}
1345 _ => continue,
1346 }
1347 let camel = name.to_upper_camel_case();
1348 uwriteln!(extra_trait_items, "type {camel} = Stub;");
1349
1350 let resource_methods = funcs.remove(&Some(*id)).unwrap_or(Vec::new());
1351 let trait_name = format!("{path}::Guest{camel}");
1352 self.generate_stub_impl(&trait_name, "", &resource_methods, interface);
1353 }
1354 format!("{path}::Guest")
1355 }
1356 None => {
1357 assert!(funcs.is_empty());
1358 "Guest".to_string()
1359 }
1360 };
1361
1362 if !root_methods.is_empty() || !extra_trait_items.is_empty() {
1363 self.generate_stub_impl(&guest_trait, &extra_trait_items, &root_methods, interface);
1364 }
1365 }
1366
1367 fn generate_stub_impl(
1368 &mut self,

Callers 2

export_interfaceMethod · 0.80
export_funcsMethod · 0.80

Calls 8

group_by_resourceFunction · 0.85
newFunction · 0.85
removeMethod · 0.80
path_to_interfaceMethod · 0.80
generate_stub_implMethod · 0.80
iterMethod · 0.45
to_stringMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected