#module #visibility #conditional #macro #assume

conditional-mod

Simple rust macro for conditional module visibility

1 unstable release

0.1.0 Mar 18, 2025

#751 in Rust patterns

Download history 11124/week @ 2025-03-22 7291/week @ 2025-03-29 9646/week @ 2025-04-05 8584/week @ 2025-04-12 8930/week @ 2025-04-19 6236/week @ 2025-04-26 8701/week @ 2025-05-03 7713/week @ 2025-05-10 2239/week @ 2025-05-17 6018/week @ 2025-05-24 11178/week @ 2025-05-31 10600/week @ 2025-06-07 7294/week @ 2025-06-14 8016/week @ 2025-06-21 7919/week @ 2025-06-28 7937/week @ 2025-07-05

33,397 downloads per month
Used in 12 crates (via solana-core)

Custom license

6KB

conditional-mod

Provides a simple macro conditional_vis_mod to change module visibility based on a condition.

Usage

Assume there is some module file my_module.rs. The visibility of the module can be changed based on conditions, such as compiler features:

// This will declare the module as public if "my_feature" is active, and private otherwise.
conditional_mod::conditional_vis_mod!(my_module, feature = "my_feature", pub);

// This will declare the module as public if "my_feature" is not active, and `pub(crate)` otherwise.
conditional_mod::conditional_vis_mod!(my_module, feature = "my_feature", pub, pub(crate));

No runtime deps