知识卡片
区分展开日志与运行日志
按原书环境,nightly 的 trace_macros! 显示调用匹配后替成什么。log_syntax! 在编译期间输出传入令牌,println! 放在输出代码里要等程序执行。check 阶段已经看到的日志可以用来确认宏收到的内容。要看完整展开结构,可在消费宏的 crate 中用 cargo expand。
相关卡片 [[在调用端查看宏展开]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Declarative macros 展开追踪和编译期打印 · 查看原书依据
Now if you run this with cargo +nightly check, you will see the log_syntax! output (The name passed to test is Sam) because it is executed at compile time. Only when we invoke cargo +nightly run will we see both the log syntax output and the println! statements that we added inside the macro.
参考来源
- 位置:《Write Powerful Rust Macros》第02章《Declarative macros》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/chapter-2.xhtml#p84)
- 结论依据:问候例子分别观察只检查和运行时会出现的日志。
- 原始内容:Now if you run this with cargo +nightly check, you will see the log_syntax! output (The name passed to test is Sam) because it is executed at compile time. Only when we invoke cargo +nightly run will we see both the log syntax output and the println! statements that we added inside the macro.