(
&mut self,
func: &Function,
params_owned: bool,
sig: &FnSig,
)
| 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(": "); |
no test coverage detected