Crates.io | mod_interface |
lib.rs | mod_interface |
version | 0.22.0 |
source | src |
created_at | 2022-05-16 21:16:51.454386 |
updated_at | 2024-06-29 18:08:38.574871 |
description | Protocol of modularity unifying interface of a module and introducing layers. |
homepage | https://github.com/Wandalen/wTools/tree/master/module/core/mod_interface |
repository | https://github.com/Wandalen/wTools/tree/master/module/core/mod_interface |
max_upload_size | |
id | 587908 |
size | 96,328 |
Protocol of modularity unifying interface of a module and introducing layers.
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
{
pub use super::orphan::*;
}
pub use protected::*;
/// Orphan namespace of the module.
pub mod orphan
{
pub use super::exposed::*;
}
/// Exposed namespace of the module.
pub mod exposed
{
pub use super::prelude::*;
}
/// Prelude to use essentials: `use my_module::prelude::*`.
pub mod prelude
{
pub use super::private::inner_is;
}
}
/// Protected namespace of the module.
pub mod protected
{
pub use super::orphan::*;
pub use super::inner::orphan::*;
}
pub use protected::*;
/// Orphan namespace of the module.
pub mod orphan
{
pub use super::exposed::*;
}
/// Exposed namespace of the module.
#[ allow( unused_imports ) ]
pub mod exposed
{
use super::*;
pub use super::prelude::*;
pub use super::inner::exposed::*;
}
/// Prelude to use essentials: `use my_module::prelude::*`.
pub mod prelude
{
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;
}
Full sample see at sample directory.
cargo add mod_interface
git clone https://github.com/Wandalen/wTools
cd wTools
cd examples/mod_interface_trivial
cargo run
git clone https://github.com/Wandalen/wTools
cd wTools
cd examples/mod_interface_trivial
cargo run