#builder-pattern #fundamental #general-purpose

no-std mod_interface

Protocol of modularity unifying interface of a module and introducing layers

28 releases (14 breaking)

new 0.16.0 Mar 16, 2024
0.14.0 Mar 16, 2024
0.6.0 Nov 4, 2023
0.1.16 Jul 19, 2022

#326 in Development tools

Download history 312/week @ 2023-11-24 372/week @ 2023-12-01 397/week @ 2023-12-08 309/week @ 2023-12-15 214/week @ 2023-12-22 129/week @ 2023-12-29 204/week @ 2024-01-05 285/week @ 2024-01-12 187/week @ 2024-01-19 176/week @ 2024-01-26 196/week @ 2024-02-02 266/week @ 2024-02-09 444/week @ 2024-02-16 473/week @ 2024-02-23 1035/week @ 2024-03-01 605/week @ 2024-03-08

2,622 downloads per month
Used in 80 crates (8 directly)

MIT license

21KB
156 lines

Module :: mod_interface

experimental rust-status docs.rs Open in Gitpod 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

Dependencies

~1.5–2.1MB
~41K SLoC