Module :: mod_interface
Protocol of modularity unifying interface of a module and introducing layers.
Basic use-case
Library file with code inner.rs
:
pub( crate ) mod private
{
pub fn inner_is() -> bool
{
true
}
}
mod_interface::mod_interface!
{
prelude use inner_is;
}
Main file that generates modules and namespaces main.rs
:
use mod_interface::mod_interface;
fn main()
{
assert_eq!( prelude::inner_is(), inner::prelude::inner_is() );
}
mod_interface::mod_interface!
{
layer inner;
}
It generates code :
use mod_interface::mod_interface;
fn main()
{
assert_eq!( prelude::inner_is(), inner::prelude::inner_is() );
}
pub mod inner
{
pub( crate ) mod private
{
pub fn inner_is() -> bool { true }
}
pub mod protected
{
pub use super::orphan::*;
}
pub use protected::*;
pub mod orphan
{
pub use super::exposed::*;
}
pub mod exposed
{
pub use super::prelude::*;
}
pub mod prelude
{
pub use super::private::inner_is;
}
}
pub mod protected
{
pub use super::orphan::*;
pub use super::inner::orphan::*;
}
pub use protected::*;
pub mod orphan
{
pub use super::exposed::*;
}
pub mod exposed
{
pub use super::prelude::*;
pub use super::inner::exposed::*;
}
pub mod prelude
{
pub use super::inner::prelude::*;
}
Debugging
To debug module interface use directive #![ debug ]
in macro mod_interface
. Let's update the main file of the example :
mod_interface::mod_interface!
{
#![ debug ]
layer inner;
}
Full sample see at sample directory.
To add to your project
cargo add mod_interface
Try out from the repository
git clone https://github.com/Wandalen/wTools
cd wTools
cd examples/mod_interface_trivial
cargo run
Try out from the repository
git clone https://github.com/Wandalen/wTools
cd wTools
cd examples/mod_interface_trivial
cargo run