( out: string[], node: NamespaceNode, holderType: string, holderField: string, isSession: boolean, defCollections: DefinitionCollections, docPrefix: string, )
| 1733 | } |
| 1734 | |
| 1735 | function emitNamespaceStruct( |
| 1736 | out: string[], |
| 1737 | node: NamespaceNode, |
| 1738 | holderType: string, |
| 1739 | holderField: string, |
| 1740 | isSession: boolean, |
| 1741 | defCollections: DefinitionCollections, |
| 1742 | docPrefix: string, |
| 1743 | ): void { |
| 1744 | const lifetimes = "<'a>"; |
| 1745 | out.push(`/// ${docPrefix}`); |
| 1746 | out.push(`#[derive(Clone, Copy)]`); |
| 1747 | out.push(`pub struct ${node.typeName}${lifetimes} {`); |
| 1748 | out.push(` pub(crate) ${holderField}: &'a ${holderType},`); |
| 1749 | out.push(`}`); |
| 1750 | out.push(""); |
| 1751 | |
| 1752 | out.push(`impl${lifetimes} ${node.typeName}${lifetimes} {`); |
| 1753 | |
| 1754 | // Sub-namespace accessors |
| 1755 | const childNames = Array.from(node.children.keys()).sort(); |
| 1756 | for (const childName of childNames) { |
| 1757 | const child = node.children.get(childName)!; |
| 1758 | const accessor = toSnakeCase(childName); |
| 1759 | const desc = isSession |
| 1760 | ? `\`session.${accessorPath(node, childName, isSession)}.*\`` |
| 1761 | : `\`${accessorPath(node, childName, isSession)}.*\``; |
| 1762 | out.push(` /// ${desc} sub-namespace.`); |
| 1763 | out.push( |
| 1764 | ` pub fn ${accessor}(&self) -> ${child.typeName}<'a> {`, |
| 1765 | ); |
| 1766 | out.push(` ${child.typeName} { ${holderField}: self.${holderField} }`); |
| 1767 | out.push(` }`); |
| 1768 | out.push(""); |
| 1769 | } |
| 1770 | |
| 1771 | // Leaf methods |
| 1772 | for (const method of node.methods) { |
| 1773 | emitNamespaceMethod(out, method, holderField, isSession, defCollections); |
| 1774 | } |
| 1775 | |
| 1776 | out.push(`}`); |
| 1777 | out.push(""); |
| 1778 | |
| 1779 | // Recursively emit child structs |
| 1780 | for (const childName of childNames) { |
| 1781 | const child = node.children.get(childName)!; |
| 1782 | const childDoc = isSession |
| 1783 | ? `\`session.${accessorPath(node, childName, isSession)}.*\` RPCs.` |
| 1784 | : `\`${accessorPath(node, childName, isSession)}.*\` RPCs.`; |
| 1785 | emitNamespaceStruct( |
| 1786 | out, |
| 1787 | child, |
| 1788 | holderType, |
| 1789 | holderField, |
| 1790 | isSession, |
| 1791 | defCollections, |
| 1792 | childDoc, |
no test coverage detected
searching dependent graphs…