To make methods from a submodule public, you have to explicitly re-export them or else make the submodule itself public:
mod foo {
mod bar {
pub fn baz() {}
}
pub use self::bar::baz;
}
This seems to hint that pub is used to indicate a thing should be public just to a module (since you can choose not to do this)
But if you use a private type defined in the outer context, you get an error if you try and make a public function involving it public in the inner context even when it's not re-exported.
mod foo {
struct Foo;
mod bar {
use super::Foo;
pub fn baz(foo: Foo) {}
}
}
results in
error[E0446]: private type `Foo` in public interface
--> src/lib.rs:7:9
|
2 | struct Foo;
| - `Foo` declared as private
...
7 | pub fn baz(foo: Foo) {}
| ^^^^^^^^^^^^^^^^^^^^ can't leak private type
What's the idiomatic way to use the pub keyword? Should it be reserved for things that are actually public or can it be used for internal modules?