知识卡片

操作参考卡 · 6074.d.1.c

可见性范围按需要扩大

理解等级:中级

pub(crate)将能力限于当前crate,pub(super)限于父模块可见范围,pub(in 路径)可限于指定祖先模块;pub(self)与默认私有相近。内部帮助函数通常不必对库用户公开。编译器提示未使用时,也应检查是否因可见性使预期调用路径根本不可达。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 4. Dependencies Visibility Syntax · 查看原书依据

      pub(crate) Accessible anywhere within the owning crate. This is particularly useful for crate-wide internal helper functions that should not be exposed to external crate users. pub(super) Accessible to the parent module of the current module and its submodules. This is occasionally useful for selectively increasing visibility in a crate that has a deep modul

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第4章《Visibility Syntax》(spine8;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch04.html;u120-ch04-008)。 - 结论依据:原文在“pub(crate)”附近的定义、例子或代码支撑本卡核心说明:pub(crate)将能力限于当前crate,pub(super)限于父模块可见范围,pub(in 路径)可限于指定祖先模块;pub(self)与默认私有相近。边界按已读前提解释;示例未执行。 - 原始内容:pub(crate) Accessible anywhere within the owning crate. This is particularly useful for crate-wide internal helper functions that should not be exposed to external crate users. pub(super) Accessible to the parent module of the current module and its submodules. This is occasionally useful for selectively increasing visibility in a crate that has a deep modul