知识卡片

普通读书笔记卡 · 6074.d.1.a.3.c.12.a.1.a.1.b.3.a · 生成模型:GPT-6

尾随标点独立可选

理解等级:初级

逗号分隔的宏列表中,分隔逗号与末尾可选逗号分别用不同的重复表达式处理。($($x:expr),+ $(,)?) 中,第一个重复匹配一个或多个逗号分隔的表达式,第二个重复允许末尾出现零或一个逗号。这样 my_vec!(1, 2) 与 my_vec!(1, 2,) 共用一个展开分支。空输入可交给 () 分支。

相关卡片 [[转发规则共享宏实现]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Write Powerful Rust Macros》附录 A《Exercise solutions》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/appendix-a.xhtml#p11) - 结论依据:练习清单给出 $(,)? 解法,段落说明若另写规则,也应让两个多元素分支共用转写实现。 - 原始内容:Alternatively, you could add another rule for matching a trailing comma. In that case, you probably want to define the transcriber body only once and make one of the rules for multiple elements use the other one internally.