Rust visibility

Posted 金庆

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Rust visibility相关的知识,希望对你有一定的参考价值。

Rust visibility: pub(in path), pub(crate), pub(super), and pub(self)

From: https://doc.rust-lang.org/reference/visibility-and-privacy.html

In addition to public and private, Rust allows users to declare an item as visible only within a given scope. The rules for pub restrictions are as follows:

  • pub(in path) makes an item visible within the provided path. path must be an ancestor module of the item whose visibility is being declared.
  • pub(crate) makes an item visible within the current crate.
  • pub(super) makes an item visible to the parent module. This is equivalent to pub(in super).
  • pub(self) makes an item visible to the current module. This is equivalent to pub(in self) or not using pub at all.

以上是关于Rust visibility的主要内容,如果未能解决你的问题,请参考以下文章

rust 学习之旅一, rust编程环境相关

rust 学习之旅一, rust编程环境相关

Rust为什么我建议你学一下 Rust | Rust 初探

Rust为什么我建议你学一下 Rust | Rust 初探

Rust 核心团队宣布新的 Rust 基金会成立

Rust 初始配置