知识卡片
宏和依赖各有作用域
普通 macro_rules! 可按文本作用域在定义之后出现。可以显式用 pub(crate) use 在 crate 内按路径提供名字,旧代码常见 #[macro_use]。#[macro_export] 将宏从 crate 根导出。展开中使用的函数仍受路径和可见性限制。导出宏要引用定义 crate 的项目时,可用 $crate::路径 清楚指定归属,同时满足目标项目的可见性。lazy_static! 用保留的 @MAKE TY 和 @TAIL 区分内部步骤。
相关卡片 [[局部绑定具有卫生性]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
- · 默认值和可变参数
原书出处 · 1 处
- Declarative macros 默认值和可变参数 · 查看原书依据
Note that we had to make our base_greeting_fn function public (and import it into our main.rs). When you consider it, the reason is once again obvious: our declarative macro is expanded in our main function.
参考来源
- 位置:《Write Powerful Rust Macros》第02章《Declarative macros》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/chapter-2.xhtml#p72)
- 结论依据:问候例子在调用者处使用辅助函数,lazy_static 内部用 $crate 指定依赖归属。
- 原始内容:Note that we had to make our base_greeting_fn function public (and import it into our main.rs). When you consider it, the reason is once again obvious: our declarative macro is expanded in our main function.