I find that in several cases I would like to have sibling modules
access private members, that is, allow "foo::bar::Bar" access the
private members of "foo::baz::Baz", but disallow any code in
"qux::*" from accessing these members.
The solution to prevent qux::* from accessing privates of bar and
baz is to introduce a private barrier module, and manually re-export
a subset of the internal API across that barrier. It'll look sort of
like
this:
pub mod foo
{
pub use self::barrier::bar::pub_bar;
pub use self::barrier::baz::pub_baz;
mod barrier
{
pub mod bar
{
pub fn priv_bar() {}
pub fn pub_bar() { ::foo::barrier::baz::priv_baz(); }
}
pub mod baz
{
pub fn priv_baz() {}
pub fn pub_baz() { ::foo::barrier::bar::priv_bar(); }
}
}
}
pub mod qux
{
pub fn test()
{
// Can't do it, as barrier is private
// ::foo::barrier::bar::priv_bar;
::foo::pub_bar();
::foo::pub_baz();
}
}
-SL
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev