知识卡片

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

路径起点随移动选择

理解等级:高级

crate:: 从当前 crate 根定位,外部路径可从外部 crate 名开始;相对路径从当前模块寻找,也可用 self 或 super。调用者和目标常一起移动时,相对关系更稳定;两者独立移动时,以 crate 根定位通常更容易保留调用。路径的每个片段仍须满足可见性。

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

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第07章 用包、crate 和模块管理增长中的项目(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c07.xhtml`,块 0079) - 结论依据:原文比较两种移动方式造成的路径变化,用具体重构说明选择依据。 - 原始内容:Choosing whether to use a relative or absolute path is a decision you’ll make based on your project, and it depends on whether you’re more likely to move item definition code separately from or together with the code that uses the item.