Module :: mod_interface

experimental rust-status docs.rs Open in Gitpod discord

Protocol of modularity unifying interface of a module and introducing layers.

Sample

Library file with code inner.rs:

```rust ignore pub( crate ) mod private { /// Routine of inner module. pub fn inner_is() -> bool { true } }

//

modinterface::modinterface! { prelude use inner_is; } ```

Main file that generates modules and namespaces main.rs : ```rust ignore modinterface::modinterface! { /// Inner. layer inner; }

//

fn main() { /* test public namespaces */ asserteq!( prelude::inneris(), true ); asserteq!( exposed::inneris(), true ); asserteq!( orphan::inneris(), true ); asserteq!( protected::inneris(), true );

/* test public module inner */ asserteq!( inner::prelude::inneris(), true ); asserteq!( inner::exposed::inneris(), true ); asserteq!( inner::orphan::inneris(), true ); asserteq!( inner::protected::inneris(), true ); } ```

It generates code :

```rust /// 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 */ asserteq!( prelude::inneris(), true ); asserteq!( exposed::inneris(), true ); asserteq!( orphan::inneris(), true ); asserteq!( protected::inneris(), true );

/* test public module inner */ asserteq!( inner::prelude::inneris(), true ); asserteq!( inner::exposed::inneris(), true ); asserteq!( inner::orphan::inneris(), true ); asserteq!( inner::protected::inneris(), true ); } ```

Full sample see at sample directory.

To add to your project

sh cargo add mod_interface

Try out from the repository

sh git clone https://github.com/Wandalen/wTools cd wTools cd sample/rust/mod_interface_trivial cargo run