← 返回刚才阅读的位置

知识卡片

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

导入保留来源信息

理解等级:中级

Rust 常引入函数的父模块,以 module::function() 指示它来自何处,而结构体或枚举通常直接导入类型名。相同范围若要使用多个同名类型,可保留模块限定,例如 fmt::Result、io::Result,也可用 as 把其中一个改成清晰的局部别名。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第07章 用包、crate 和模块管理增长中的项目(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c07.xhtml`,块 0148) - 结论依据:原文使用两种函数导入的等价结果解释保留模块限定为何提高可读性。 - 原始内容:Although both Listing 7-11 and Listing 7-13 accomplish the same task, Listing 7-11 is the idiomatic way to bring a function into scope with use. Bringing the function’s parent module into scope with use means we have to specify the parent module when calling the function.