macro_rules! mods {
() => { ... };
($mod_vis:vis mod $use_vis:vis use $($module:ident),+; $($rest:tt)*) => { ... };
($mod_vis:vis mod $($module:ident),+; $($rest:tt)*) => { ... };
($use_vis:vis use $($mod_path:path),+; $($rest:tt)*) => { ... };
($use_vis:vis use $root:ident::{$($mod_path:path),+}; $($rest:tt)*) => { ... };
}Expand description
Flexible and powerful module declarations.
§Syntax
There’s three different patterns the macro matches against:
- Define modules and use the contents (
::*). - Define modules.
- Use the contents of modules that are already in scope.
- Use the contents of modules that are in a root module.
For example,
crate::{mod1, mod2}instead ofcrate::mod1, crate::mod2.
After each pattern, you can type a semicolon (;) and make another one!
§Examples
This showcases each of the three patterns:
ⓘ
dry_mods::mods! {
// `foo` and `bar` will be defined with the `pub(crate)` visibility but the contents will be completely public.
pub(crate) mod pub use foo, bar;
// `baz` is totally private, but the contents are exposed in the module where `mods!` was called.
use baz;
// `my_mod` is now a public module.
pub mod my_mod;
// Use the root module for crate internals.
pub(crate) use crate::{int1, int2, int3, int4, int5};
}
// Generates:
pub(crate) mod foo;
pub(crate) mod bar;
pub use foo::*;
pub use bar::*;
use baz::*;
pub mod my_mod;
pub(crate) crate::{int1::*, int2::*, int3::*, int4::*, int5::*};