知识卡片

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

导入名称受作用域限制

理解等级:中级

use 给能够访问的既有路径建立当前作用域内的简称;它也受隐私检查。父作用域引入的 hosting 不会自动成为子模块中的裸名。调用移入子模块后,可把 use 一起移入,或通过 super::hosting 显式引用父级的导入名。

相关卡片 [[模块可见性逐段检查]]

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第07章 用包、crate 和模块管理增长中的项目(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c07.xhtml`,块 0136) - 结论依据:将调用移进 customer 模块后的失败,直接证明 use 的简称只在相应作用域可用。 - 原始内容:Note that use only creates the shortcut for the particular scope in which the use occurs. Listing 7-12 moves the eat_at_restaurant function into a new child module named customer, which is then a different scope than the use statement, so the function body won’t compile.