docs

您正在閱讀 v0.1.0 的文件。Nabi 0.1.0 已停止支援。 最新版本:v0.1.3 →

本頁尚未翻譯,以下為英文原文。

#E0034: item is private

The item, field or method is private to another module (or pub(pkg) in another package), so it cannot be used here; a private item is not visible to child modules either. Mark it where it is defined with the visibility the message names: pub(pkg) for the rest of its package, pub for other packages. Or use a public item instead.

nabi
mod geo {
    fn area(w: i32, h: i32) -> i32 { w * h }
}
println(f"{geo::area(2, 3)}");
error[E0034]: function `geo::area` is private to module `geo` and cannot be used from `<root>` (add `pub(pkg)` to expose it)
  --> main.nabi:4:12
   |
 4 | println(f"{geo::area(2, 3)}");
   |            ^^^^^^^^^^^^^^^

Add pub(pkg):

nabi
mod geo {
    pub(pkg) fn area(w: i32, h: i32) -> i32 { w * h }
}
println(f"{geo::area(2, 3)}");
6

Items are private to their module unless marked pub (5.6 Visibility).

Related: E0033 invalid re-export, E0016 visibility where it has no meaning

Found a mistake? Edit this page on GitHub. Last updated