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)*) => { ... };
}
Expand description
Declares modules simply.
§Examples
To declare multiple public modules, simply place pub
before a module list:
ⓘ
mods::mods! {
pub puppy, kitty;
}
This works for all visibility modifiers:
ⓘ
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:
ⓘ
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:
ⓘ
pub mod puppy, kitty;
Or a syntax that matches use
imports:
ⓘ
pub mod {puppy, kitty};