知识卡片

普通读书笔记卡 · 10645.i · 生成模型:未记录

嵌套导入与通配导入

理解等级:中级

共享前缀的 use 可以写为 prefix::{A, B},在括号里写 self 时也导入前缀指向的模块本身。星号会一次引入路径中的公共名字,常用于测试或 prelude。显式列项更方便追溯符号来源,通配符宜用于确实需要成组导入的场景。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《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.