So I want to make a nice and tidy interface for my library crate. So instead letting a user have access to sub-modules, I want them to be able to reach structs/etc from the library root (lib.rs):
mod sh2;
pub use sh2::Sh2;
And in the client code, I try to access about thusly:
use libname;
let sh2 = libname::Sh2::new();
However, this will fail with:
error: module sh2 is private
Which was the whole point.
Doing a pub mod sh2; makes things compile, but we loose the encapsulation.
So was this by design? Am I doing something wrong?
No, in my case Sh2 is pub. I should think Sh2 should always be pub for things to even work. You can't access a private struct in a pub mod I don't think.
I'm sure the examples in say 'the book' work, in which submodules of library submodules can be exported in this way. But specifically in the library root (lib.rs) this does not seem to work.
Thanks for your thorough reply. And sorry to waste your time, I'm an idiot. There was a use libname::sh2 in the root of the client lib. I should have made my own stripped down example first.