知识卡片
嵌套导入与通配导入
共享前缀的 use 可以写为 prefix::{A, B},在括号里写 self 时也导入前缀指向的模块本身。星号会一次引入路径中的公共名字,常用于测试或 prelude。显式列项更方便追溯符号来源,通配符宜用于确实需要成组导入的场景。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 用包、crate 和模块管理增长中的项目 Using External Packages · 查看原书依据
This use statement brings all public items defined in std::collections into the current scope. Be careful when using the glob operator! Glob can make it harder to tell what names are in scope and where a name used in your program was defined.
参考来源
- 位置:《The Rust Programming Language(第2版)》第07章 用包、crate 和模块管理增长中的项目(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c07.xhtml`,块 0205)
- 结论依据:原文用 std::collections::* 说明通配导入范围,同时指出名称来源变得模糊。
- 原始内容:This use statement brings all public items defined in std::collections into the current scope. Be careful when using the glob operator! Glob can make it harder to tell what names are in scope and where a name used in your program was defined.