[][src]Macro mods::mods

macro_rules! mods {
    () => { ... };
    (pub $($module:ident,)+; $($rest:tt)*) => { ... };
    (pub($vis:ident) $($module:ident,)+; $($rest:tt)*) => { ... };
    (pub(in $vis:path) $($module:ident,)+; $($rest:tt)*) => { ... };
    ($($module:ident,)+; $($rest:tt)*) => { ... };
    (pub $($module:ident),+; $($rest:tt)*) => { ... };
    (pub($vis:ident) $($module:ident),+; $($rest:tt)*) => { ... };
    (pub(in $vis:path) $($module:ident),+; $($rest:tt)*) => { ... };
    ($($module:ident),+; $($rest:tt)*) => { ... };
}

Declares modules simply.

Examples

To declare multiple public modules, simply place pub before a module list:

This example is not tested
mods::mods! {
    pub puppy, kitty;
}

This works for all visibility modifiers:

This example is not tested
mods::mods! {
    pub a, b;        // Visible anywhere, even outside the module
    pub(crate) c, d; // Visible anywhere within the crate
    pub(super) e, f; // Visible to the parent module
    g, h;            // Visible to the current module
}

Without the mods! macro, the same code is much less succinct. This is what the macro expands out to:

This example is not tested
pub mod a;
pub mod b;
pub(crate) mod c;
pub(crate) mod d;
pub(super) mod e;
pub(super) mod f;
mod g;
mod h;

Wishful Thinking

It would be wonderful if we could instead have:

This example is not tested
pub mod puppy, kitty;

Or a syntax that matches use imports:

This example is not tested
pub mod {puppy, kitty};