知识卡片
通配导入放大未来名称冲突
use module::*把模块公开名全部带入作用域,未来依赖新增trait后,可能使同一类型上的方法调用出现多个候选。显式导入更清楚地固定使用面;本地普通名称有优先级,并非任何新增都冲突。受控内部模块或专门prelude可按便利与风险取舍。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 4. Dependencies Item 23: Avoid wildcard imports · 查看原书依据
wildcard imports Rust’s use statement pulls in a named item from another crate or module and makes that name available for use in the local module’s code without qualification. A wildcard import (or glob import) of the form use somecrate::module::* says that every public symbol from that module should be added to the local namespace. As described in Item 21,
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第4章《Item 23: Avoid wildcard imports》(spine8;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch04.html;u122-ch04-010)。
- 结论依据:原文在“wildcard import”附近的定义、例子或代码支撑本卡核心说明:use module::*把模块公开名全部带入作用域,未来依赖新增trait后,可能使同一类型上的方法调用出现多个候选。边界按已读前提解释;示例未执行。
- 原始内容:wildcard imports Rust’s use statement pulls in a named item from another crate or module and makes that name available for use in the local module’s code without qualification. A wildcard import (or glob import) of the form use somecrate::module::* says that every public symbol from that module should be added to the local namespace. As described in Item 21,