Crate mod_interface
source ·Expand description
Protocol of modularity unifying interface of a module and introducing layers.
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
{
/// Routine of inner module.
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!
{
/// Inner.
layer inner;
}It generates code :
use mod_interface::mod_interface;
//
fn main()
{
assert_eq!( prelude::inner_is(), inner::prelude::inner_is() );
}
//
/// Inner.
pub mod inner
{
pub( crate ) mod private
{
/// Routine of inner module.
pub fn inner_is() -> bool { true }
}
/// Protected namespace of the module.
pub mod protected
{
#[ doc( inline ) ]
pub use super::orphan::*;
}
#[ doc( inline ) ]
pub use protected::*;
/// Orphan namespace of the module.
pub mod orphan
{
#[ doc( inline ) ]
pub use super::exposed::*;
}
/// Exposed namespace of the module.
pub mod exposed
{
#[ doc( inline ) ]
pub use super::prelude::*;
}
/// Prelude to use essentials: `use my_module::prelude::*`.
pub mod prelude
{
#[ doc( inline ) ]
pub use super::private::inner_is;
}
}
/// Protected namespace of the module.
pub mod protected
{
#[ doc( inline ) ]
pub use super::orphan::*;
#[ doc( inline ) ]
pub use super::inner::orphan::*;
}
#[ doc( inline ) ]
pub use protected::*;
/// Orphan namespace of the module.
pub mod orphan
{
#[ doc( inline ) ]
pub use super::exposed::*;
}
/// Exposed namespace of the module.
pub mod exposed
{
#[ doc( inline ) ]
pub use super::prelude::*;
#[ doc( inline ) ]
pub use super::inner::exposed::*;
}
/// Prelude to use essentials: `use my_module::prelude::*`.
pub mod prelude
{
#[ doc( inline ) ]
pub use super::inner::prelude::*;
}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 ]
/// Inner.
layer inner;
}The directive adds stdout output with module structure. For the case above output looks :
ⓘ
= original :
#! [debug] /// Inner.
layer inner ;
= result :
#[doc = " Inner."]
pub mod inner ;
#[doc(inline)]
pub use protected :: * ;
#[doc = r" Protected namespace of the module."]
pub mod protected
{
#[doc(inline)]
pub use super :: orphan :: * ;
#[doc(inline)]
#[doc = " Inner."]
pub use super :: inner :: orphan :: * ;
}
#[doc = r" Orphan namespace of the module."]
pub mod orphan
{
#[doc(inline)]
pub use super :: exposed :: * ;
}
#[doc = r" Exposed namespace of the module."]
pub mod exposed
{
#[doc(inline)]
pub use super :: prelude :: * ;
#[doc(inline)]
#[doc = " Inner."]
pub use super :: inner :: exposed :: * ;
}
#[doc = r" Prelude to use essentials: `use my_module::prelude::*`."]
pub mod prelude
{
#[doc(inline)]
#[doc = " Inner."]
pub use super :: inner :: prelude :: * ;
}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
Modules
- Namespace with dependencies.
- Exposed namespace of the module.
- Protocol of modularity unifying interface of a module and introducing layers.
- Orphan namespace of the module.
- Prelude to use essentials:
use my_module::prelude::*. - Protected namespace of the module.
Macros
- Protocol of modularity unifying interface of a module and introducing layers.