知识卡片
在调用端查看宏展开
cargo expand 可在消费端观察现有源代码的展开视图。用它检查生成实现的名字、作用域和签名,以及展开前后哪些项目还存在。宏库目录里的展开显示宏库调用的宏。原书还展示把展开文本临时保存,获得更具体的定位。展开视图适合诊断,实际语义仍以正常调用编译和运行结果判断。
相关卡片 [[生成代码要在调用端验证]]、[[区分展开日志与运行日志]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
- · 展开检查
原书出处 · 1 处
- A “Hello, World” procedural macro 展开检查 · 查看原书依据
You can also use expand within the hello-world-macro library, but that will only show you how the macros you use—not the ones you create for others—are expanded, similar to how check will only point out errors in your code and not in generated code.
参考来源
- 位置:《Write Powerful Rust Macros》第03章《A “Hello, World” procedural macro》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/chapter-3.xhtml#p76)
- 结论依据:书中用被拼错的 self 展示查看生成签名的价值,并区分在哪里运行 expand。
- 原始内容:You can also use expand within the hello-world-macro library, but that will only show you how the macros you use—not the ones you create for others—are expanded, similar to how check will only point out errors in your code and not in generated code.