知识卡片
抽象层次决定是否需要宏
函数抽象同类值的差异,泛型抽象满足约束的类型差异,宏则可抽象表达式、标识符或类型等语法片段的重复结构。只有结构生成确有收益时才引入宏,避免把普通函数能表达的逻辑隐藏进新语法。宏基于token不等于自动理解全部类型语义。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 5. Tooling Item 28: Use macros judiciously · 查看原书依据
A macro abstracts away the difference between different fragments of the program that play the same role (type, identifier, expression, etc.); the implementation can then include any code that makes use of those fragments in the same role. Rust provides two ways to define macros: Declarative macros, also known as “macros by example,” allow the insertion of a
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第5章《Item 28: Use macros judiciously》(spine9;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch05.html;u140-ch05-006)。
- 结论依据:原文在“A macro abstracts away”附近的定义、例子或代码支撑本卡核心说明:函数抽象同类值的差异,泛型抽象满足约束的类型差异,宏则可抽象表达式、标识符或类型等语法片段的重复结构。边界按已读前提解释;示例未执行。
- 原始内容:A macro abstracts away the difference between different fragments of the program that play the same role (type, identifier, expression, etc.); the implementation can then include any code that makes use of those fragments in the same role. Rust provides two ways to define macros: Declarative macros, also known as “macros by example,” allow the insertion of a