知识卡片
宏展开后仍要检查
Rust 宏把调用中的语法作为输入,在编译过程中生成普通 Rust 代码。例如,派生宏可以生成一个 trait 的实现,编译器仍要检查这个实现。宏自身的执行成本主要体现在构建期,展开结果增加的运行时代码、二进制体积和执行成本仍取决于实际生成内容。
相关卡片 [[过程宏的三种接口]]、[[生成代码要在调用端验证]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Going meta 从请求程序到元编程 · 查看原书依据
In brief, metaprogramming is when you write code that will use other code as a data input. That means you can manipulate existing code, generate additional code, or add new capabilities to an application.
参考来源
- 位置:《Write Powerful Rust Macros》第01章《Going meta》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/chapter-1.xhtml#p13)
- 结论依据:原文把宏展开和后续 lint、类型检查及编译联系起来,并将编译成本对照运行时反射。
- 原始内容:In brief, metaprogramming is when you write code that will use other code as a data input. That means you can manipulate existing code, generate additional code, or add new capabilities to an application.