← 返回刚才阅读的位置

知识卡片

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

属性宏的两个输入

理解等级:中级

Rust 属性过程宏接收两个流。第一个是调用属性携带的参数,如 #[public(exclude(fourth, third))] 的 exclude(fourth, third)。第二个是被标注的条目,可从其 AST 读到其他仍存在的条目属性和字段属性。属性宏自身在展开时是活跃的,替换原条目可以留下改写结果或不产出条目。派生宏的辅助属性则保留在输入项上,从语法树读取。

相关卡片 [[派生辅助属性配置展开]]、[[属性宏参数的结构化解析]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Builder with attributes 属性宏输入与参数解析 · 查看原书依据

      Now let’s move on to the library code and some notable differences. With a derive macro, we had attributes in the root of the token stream or on individual fields. With an attribute macro, you can still find attributes on the individual fields, and other attributes can still be found in the root of the AST. But one thing is very much unlike a derive macro: our annotation is extremely flexible.

    参考来源

    - 位置:《Write Powerful Rust Macros》第08章《Builder with attributes》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/chapter-8.xhtml#p174) - 结论依据:8.7 用 public(exclude(...)) 区分宏自身参数令牌、被标注条目的输入以及语法树上的其他属性。 - 原始内容:Now let’s move on to the library code and some notable differences. With a derive macro, we had attributes in the root of the token stream or on individual fields. With an attribute macro, you can still find attributes on the individual fields, and other attributes can still be found in the root of the AST. But one thing is very much unlike a derive macro: our annotation is extremely flexible.