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

Method print_docs_and_params

crates/rust/src/interface.rs:1474–1589  ·  view source on GitHub ↗
(
        &mut self,
        func: &Function,
        params_owned: bool,
        sig: &FnSig,
    )

Source from the content-addressed store, hash-verified

1472 }
1473
1474 fn print_docs_and_params(
1475 &mut self,
1476 func: &Function,
1477 params_owned: bool,
1478 sig: &FnSig,
1479 ) -> Vec<String> {
1480 self.rustdoc(&func.docs);
1481 self.rustdoc_params(&func.params, "Parameters");
1482 // TODO: re-add this when docs are back
1483 // self.rustdoc_params(&func.results, "Return");
1484
1485 // TODO: should probably return `impl Future` in traits instead of
1486 // having an `async fn` but that'll require more plumbing here.
1487 self.push_str("#[allow(async_fn_in_trait)]\n");
1488
1489 if !sig.private {
1490 self.push_str("pub ");
1491 }
1492 if sig.unsafe_ {
1493 self.push_str("unsafe ");
1494 }
1495 if sig.async_ {
1496 self.push_str("async ");
1497 }
1498 self.push_str("fn ");
1499 let func_name = if sig.use_item_name {
1500 if let FunctionKind::Constructor(_) = &func.kind {
1501 "new"
1502 } else {
1503 func.item_name()
1504 }
1505 } else {
1506 func.item_name()
1507 };
1508 self.push_str(&to_rust_ident(func_name));
1509 if let Some(generics) = &sig.generics {
1510 self.push_str(generics);
1511 }
1512 self.push_str("(");
1513 if let Some(arg) = &sig.self_arg {
1514 self.push_str(arg);
1515 self.push_str(",");
1516 }
1517 let mut params = Vec::new();
1518 for (
1519 i,
1520 Param {
1521 name, ty: param, ..
1522 },
1523 ) in func.params.iter().enumerate()
1524 {
1525 if i == 0 && sig.self_is_first_param {
1526 params.push("self".to_string());
1527 continue;
1528 }
1529 let name = to_rust_ident(name);
1530 self.push_str(&name);
1531 self.push_str(": ");

Callers 1

print_signatureMethod · 0.80

Calls 10

to_rust_identFunction · 0.85
newFunction · 0.85
rustdocMethod · 0.80
rustdoc_paramsMethod · 0.80
type_mode_forMethod · 0.80
push_strMethod · 0.45
iterMethod · 0.45
pushMethod · 0.45
to_stringMethod · 0.45
print_tyMethod · 0.45

Tested by

no test coverage detected