Consider the following code in my library:
pub struct Foo;
impl Foo {
fn helper(&self) { /* .. */ }
}
pub fn do_something(foo: &Foo) {
foo.helper();
}
The users of my library should be able to use Foo and do_something(), but shall never call helper(). Everything works fine with the code above. But now imagine the code gets huge and I want to separate those definitions into their own files/modules -- they are then pulled back into the root-namespace with pub use. See here:
mod foo { // module contents in `src/foo.rs`
pub struct Foo;
impl Foo {
fn helper(&self) { /* .. */ }
}
}
mod do_something { // module contents in `src/do_something.rs`
use super::Foo;
pub fn do_something(foo: &Foo) {
foo.helper();
}
}
pub use foo::Foo;
pub use do_something::do_something;
Now the compiler complains that helper() is private. Indeed it is, but I still want do_something() be able to use it. But I don't want my users to use it. How can I do that?
My attempted solution boils down to "How to access private items of sibling modules?". So answering that question would help me. But providing an alternative solution/a workaround would also be great!