#builder-pattern #general-purpose #fundamental

no-std mod_interface

Protocol of modularity unifying interface of a module and introducing layers

31 releases (17 breaking)

0.19.0 May 14, 2024
0.17.0 Mar 26, 2024
0.6.0 Nov 4, 2023
0.1.16 Jul 19, 2022

#92 in Development tools

Download history 174/week @ 2024-02-01 256/week @ 2024-02-08 434/week @ 2024-02-15 490/week @ 2024-02-22 909/week @ 2024-02-29 1688/week @ 2024-03-07 4288/week @ 2024-03-14 2479/week @ 2024-03-21 672/week @ 2024-03-28 736/week @ 2024-04-04 518/week @ 2024-04-11 390/week @ 2024-04-18 755/week @ 2024-04-25 674/week @ 2024-05-02 4630/week @ 2024-05-09 1861/week @ 2024-05-16

7,965 downloads per month
Used in 84 crates (9 directly)

MIT license

22KB
156 lines

Module :: mod_interface

experimental rust-status docs.rs discord

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
  {
    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.
pub mod exposed
{
  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::*;
}

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 ]
  /// Inner.
  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

Dependencies

~1.6–2.2MB
~43K SLoC