14 releases
0.1.16 | Jul 19, 2022 |
---|---|
0.1.15 | Jul 19, 2022 |
0.1.4 | Jun 29, 2022 |
0.1.3 | May 25, 2022 |
#353 in Development tools
3,143 downloads per month
Used in 59 crates
(3 directly)
2MB
54K
SLoC
Module :: mod_interface
Protocol of modularity unifying interface of a module and introducing layers.
Sample
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
:
mod_interface::mod_interface!
{
/// Inner.
layer inner;
}
//
fn main()
{
/* test public namespaces */
assert_eq!( prelude::inner_is(), true );
assert_eq!( exposed::inner_is(), true );
assert_eq!( orphan::inner_is(), true );
assert_eq!( protected::inner_is(), true );
/* test public module `inner` */
assert_eq!( inner::prelude::inner_is(), true );
assert_eq!( inner::exposed::inner_is(), true );
assert_eq!( inner::orphan::inner_is(), true );
assert_eq!( inner::protected::inner_is(), true );
}
It generates code :
/// 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::*;
}
fn main()
{
/* test public namespaces */
assert_eq!( prelude::inner_is(), true );
assert_eq!( exposed::inner_is(), true );
assert_eq!( orphan::inner_is(), true );
assert_eq!( protected::inner_is(), true );
/* test public module `inner` */
assert_eq!( inner::prelude::inner_is(), true );
assert_eq!( inner::exposed::inner_is(), true );
assert_eq!( inner::orphan::inner_is(), true );
assert_eq!( inner::protected::inner_is(), true );
}
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 sample/rust/mod_interface_trivial
cargo run
Dependencies
~4.5MB
~127K SLoC